suwako / UnixMenu アーカイブ

このリポジトリはアーカイブされています。読むだけで、プッシュやイシューの変更は出来ません。

SVNからのミラー

諏訪子 <suwako@076.moe>、2026-01-06 21:47
コミット 7603358afea742ceea6cb4238b1489c6075c8660 ・ファイルを見る

20個のファイル、+816 -0

追加 CHANGELOG.md
@@ -0,0 +1,7 @@
1+# 0.2.0 (2025/07/07)
2+* .desktopファイルがなければ、$PATHから実効してみる様に
3+* um.desktopファイルの追加
4+* CLI用プログラムの場合は端末にラウンチする様に
5+
6+# 0.1.0 (2024/09/16)
7+* 開始
追加 LICENSE.txt
@@ -0,0 +1,13 @@
1+Copyright © 2018-2024 by 076.moe
2+
3+Permission to use, copy, modify, and/or distribute this software for any
4+purpose with or without fee is hereby granted, provided that the above
5+copyright notice and this permission notice appear in all copies.
6+
7+THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
8+TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9+FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
10+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
11+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
12+ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
13+SOFTWARE.
追加 Makefile
@@ -0,0 +1,97 @@
1+UNAME_S != uname -s
2+UNAME_M != uname -m
3+OS = ${UNAME_S}
4+ARCH = ${UNAME_M}
5+
6+.if ${UNAME_S} == "OpenBSD"
7+OS = openbsd
8+.elif ${UNAME_S} == "NetBSD"
9+OS = netbsd
10+.elif ${UNAME_S} == "FreeBSD"
11+OS = freebsd
12+.elif ${UNAME_S} == "Dragonfly"
13+OS = dragonfly
14+.elif ${UNAME_S} == "Linux"
15+OS = linux
16+.endif
17+
18+.if ${UNAME_M} == "x86_64"
19+ARCH = amd64
20+.endif
21+
22+NAME != cat main.c | grep "const char \*sofname" | awk '{print $$5}' |\
23+ sed "s/\"//g" | sed "s/;//"
24+VERSION != cat main.c | grep "const char \*version" | awk '{print $$5}' |\
25+ sed "s/\"//g" | sed "s/;//"
26+
27+PREFIX = /usr/local
28+.if ${OS} == "linux"
29+PREFIX = /usr
30+.endif
31+
32+CC = cc
33+FILES = main.c src/*.c
34+
35+CFLAGS = -Wall -Wextra -I/usr/include -L/usr/lib
36+.if ${OS} == "netbsd"
37+CFLAGS += -I/usr/X11R7/include -I/usr/X11R7/include/freetype2 -L/usr/X11R7/lib
38+.elif ${OS} == "openbsd"
39+CFLAGS += -I/usr/X11R6/include -I/usr/X11R6/include/freetype2 -L/usr/X11R6/lib
40+.elif ${OS} == "freebsd"
41+CFLAGS += -I/usr/local/include -I/usr/local/include/X11\
42+ -I /usr/local/include/freetype2\
43+ -L/usr/local/lib
44+.elif ${OS} == "linux"
45+CFLAGS += -I/usr/include/freetype2
46+.endif
47+
48+LDFLAGS = -lc -lX11 -lXft
49+SLIB = -lxcb
50+.if ${OS} == "openbsd"
51+SLIB += -lfontconfig -lz -lexpat -lfreetype -lXrender -lXau -lXdmcp
52+.elif ${OS} == "freebsd"
53+SLIB += -lthr -lfontconfig -lfreetype -lXrender -lXau -lXdmcp -lexpat -lz -lbz2\
54+ -lpng16 -lbrotlidec -lm -lbrotlicommon
55+.elif ${OS} == "netbsd"
56+SLIB += -lfontconfig -lfreetype -lXau -lXdmcp -lgcc -lexpat -lz -lbz2 -lXrandr\
57+ -lXrender -lXext -lX11
58+.elif ${OS} == "linux"
59+SLIB += -lfontconfig -lfreetype -lXrender -lXau -lXdmcp -lX11\
60+ -lexpat -lpng16 -lbz2 -lz\
61+ -lbrotlidec -lbrotlicommon
62+.endif
63+
64+all:
65+ ${CC} -O3 ${CFLAGS} -o ${NAME} ${FILES} -static ${LDFLAGS} ${SLIB}
66+ strip ${NAME}
67+
68+debug:
69+ ${CC} -g ${CFLAGS} -o ${NAME} ${FILES} ${LDFLAGS}
70+
71+clean:
72+ rm -rf ${NAME}
73+
74+dist:
75+ mkdir -p ${NAME}-${VERSION} release/src
76+ cp -R LICENSE.txt Makefile README.md CHANGELOG.md\
77+ main.c ${NAME}.desktop ${NAME}-${VERSION}
78+ tar zcfv release/src/${NAME}-${VERSION}.tar.gz ${NAME}-${VERSION}
79+ rm -rf ${NAME}-${VERSION}
80+
81+release:
82+ mkdir -p release/bin/${VERSION}/${OS}/${ARCH}
83+ ${CC} -O3 ${CFLAGS} -o release/bin/${VERSION}/${OS}/${ARCH}/${NAME} ${FILES}\
84+ -static ${LDFLAGS} ${SLIB}
85+ strip release/bin/${VERSION}/${OS}/${ARCH}/${NAME}
86+
87+install:
88+ mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${PREFIX}/share/applications
89+ cp -f ${NAME} ${DESTDIR}${PREFIX}/bin
90+ cp -f ${NAME}.desktop ${DESTDIR}${PREFIX}/share/applications
91+ chmod 644 ${DESTDIR}${PREFIX}/share/applications/${NAME}.desktop
92+ chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME}
93+
94+uninstall:
95+ rm -f ${DESTDIR}${PREFIX}/bin/${NAME}
96+
97+.PHONY: all debug clean dist release install uninstall
追加 README.md
@@ -0,0 +1,21 @@
1+# um
2+只のランチャー。
3+
4+Xorg以外、従属ライブラリを使いません。
5+
6+## インストールする方法 | Installation
7+### BSD
8+```sh
9+make
10+doas make install
11+```
12+
13+### Linux
14+```sh
15+bmake
16+doas bmake install
17+```
18+
19+![](scrot1.png)
20+
21+![](scrot2.png)
追加 fonts.dir
@@ -0,0 +1,1 @@
1+0
追加 fonts.scale
@@ -0,0 +1,1 @@
1+0
追加 main.c
@@ -0,0 +1,114 @@
1+#include <stdio.h>
2+#include <stdlib.h>
3+
4+#include "src/control.h"
5+#include "src/program.h"
6+#include "src/display.h"
7+#include "src/parser.h"
8+#include "src/utils.h"
9+
10+XftColor color, selcolor;
11+Colormap colormap;
12+XftDraw *draw;
13+XftFont *font;
14+Visual *visual;
15+
16+const char *sofname = "um";
17+const char *version = "0.2.0";
18+
19+int main() {
20+ Display *display;
21+ Window window;
22+ XEvent event;
23+ int screen;
24+ GC gc = NULL;
25+ XGCValues values;
26+ char input[MAX_NAME_LEN] = {0};
27+ int sel = 0;
28+
29+ fetch_programs();
30+
31+ display = XOpenDisplay(NULL);
32+ if (display == NULL) {
33+ fprintf(stderr, "画面を開けられません。\n");
34+ exit(1);
35+ }
36+
37+ screen = DefaultScreen(display);
38+
39+ int screen_width = DisplayWidth(display, screen);
40+ int screen_height = DisplayHeight(display, screen);
41+ window_width = screen_width / 4;
42+ window_height = screen_height / 4;
43+ int window_x = (screen_width - window_width) / 2;
44+ int window_y = (screen_height - window_height) / 2;
45+
46+ window = XCreateSimpleWindow(display, RootWindow(display, screen),
47+ window_x, window_y, window_width, window_height, 1, BLACK, BLACK);
48+ if (!window) {
49+ cleanup(display, window, gc, &color, &selcolor, draw, font, colormap, visual);
50+ }
51+
52+ XSetWindowBackground(display, window, BGCOL);
53+
54+ XSelectInput(display, window,
55+ ExposureMask | KeyPressMask | StructureNotifyMask | ButtonPressMask);
56+
57+ gc = XCreateGC(display, window, 0, &values);
58+ if (!gc) {
59+ cleanup(display, window, gc, &color, &selcolor, draw, font, colormap, visual);
60+ fprintf(stderr, "GCを作れません。\n");
61+ exit(1);
62+ }
63+
64+ visual = DefaultVisual(display, screen);
65+
66+ colormap = XCreateColormap(display, window, visual, AllocNone);
67+ if (colormap == None) {
68+ cleanup(display, window, gc, &color, &selcolor, draw, font, colormap, visual);
69+ fprintf(stderr, "カラーマップを作れません。\n");
70+ exit(1);
71+ }
72+
73+ draw = XftDrawCreate(display, window, visual, colormap);
74+ if (!draw) {
75+ cleanup(display, window, gc, &color, &selcolor, draw, font, colormap, visual);
76+ fprintf(stderr, "ドローを作れません。\n");
77+ exit(1);
78+ }
79+
80+ font = XftFontOpenName(display, screen, "Noto Sans CJK-12");
81+ if (!font) {
82+ cleanup(display, window, gc, &color, &selcolor, draw, font, colormap, visual);
83+ fprintf(stderr, "フォントの読み込みに失敗。\n");
84+ exit(1);
85+ }
86+
87+ if (!XftColorAllocName(display, visual, colormap, "white", &color)) {
88+ cleanup(display, window, gc, &color, &selcolor, draw, font, colormap, visual);
89+ fprintf(stderr, "色の役割に失敗。\n");
90+ }
91+
92+ if (!XftColorAllocName(display, visual, colormap, "black", &selcolor)) {
93+ cleanup(display, window, gc, &color, &selcolor, draw, font, colormap, visual);
94+ fprintf(stderr, "選択色の役割に失敗。\n");
95+ }
96+
97+ XMapWindow(display, window);
98+
99+ while (1) {
100+ XNextEvent(display, &event);
101+
102+ if (event.type == Expose || event.type == ConfigureNotify) {
103+ control_expose(display, window, gc, &event, input, &sel);
104+ } else if (event.type == KeyPress) {
105+ control_keypress(display, window, gc, &event, input, &sel);
106+ } else if (event.type == ButtonPress) {
107+ control_buttonpress(&event, programs, item_height);
108+ }
109+ }
110+
111+ cleanup(display, window, gc, &color, &selcolor, draw, font, colormap, visual);
112+
113+ return 0;
114+}
追加 scrot1.png

バイナリファイル

追加 scrot2.png

バイナリファイル

追加 src/control.c
@@ -0,0 +1,91 @@
1+#include "control.h"
2+#include "display.h"
3+#include "utils.h"
4+
5+#include <stdio.h>
6+#include <string.h>
7+#include <stdlib.h>
8+
9+void control_expose(
10+ Display *display, Window window, GC gc, XEvent *event, char *input, int *sel) {
11+ if (event->type == ConfigureNotify)
12+ calculate_dimensions(event->xconfigure.width, event->xconfigure.height);
13+ filterdisplay(display, window, gc, input, *sel);
14+}
15+
16+void control_keypress(
17+ Display *display, Window window, GC gc, XEvent *event, char *input, int *sel) {
18+ char buf[32];
19+ KeySym keysym;
20+ int len = XLookupString(&event->xkey, buf, sizeof(buf) - 1, &keysym, NULL);
21+
22+ if (keysym == XK_Up) {
23+ if (*sel > 0) {
24+ (*sel)--;
25+ if (*sel < topidx) topidx--;
26+ }
27+ } else if (keysym == XK_Down) {
28+ int filteredcount = filtercount(input);
29+ if (*sel < filteredcount - 1) {
30+ (*sel)++;
31+ if (*sel >= topidx + display_items) topidx++;
32+ }
33+ } else if (keysym == XK_Page_Up) {
34+ if (*sel > 0) {
35+ *sel -= display_items;
36+ if (*sel < topidx) topidx -= display_items;
37+ }
38+ } else if (keysym == XK_Page_Down) {
39+ int filteredcount = filtercount(input);
40+ if (*sel < filteredcount - 1) {
41+ *sel += display_items;
42+ if (*sel >= topidx + display_items) topidx += display_items;
43+ }
44+ } else if (keysym == XK_BackSpace && strlen(input) > 0) {
45+ input[strlen(input) - 1] = '\0';
46+ *sel = 0;
47+ topidx = 0;
48+ } else if (keysym == XK_Return) {
49+ int visible_index = 0;
50+ int found = 0;
51+ for (int i = 0; i < programcount; i++) {
52+ if (!strcasestr(programs[i].name, input)) continue;
53+ if (visible_index == *sel) {
54+ launch_program(programs[i].exec, programs[i].term);
55+ found = 1;
56+ break;
57+ }
58+ visible_index++;
59+ }
60+
61+ if (found == 0 && launch_path(input)) {
62+ launch_program(input, "false");
63+ }
64+ exit(0);
65+ } else if (keysym == XK_Escape) {
66+ exit(0);
67+ } else if (len > 0 && len < MAX_NAME_LEN - 1) {
68+ strncat(input, buf, len);
69+ *sel = 0;
70+ topidx = 0;
71+ }
72+
73+ filterdisplay(display, window, gc, input, *sel);
74+}
75+
76+void control_buttonpress(XEvent *event, Program *programs, int item_height) {
77+ int x = event->xbutton.x;
78+ int y = event->xbutton.y;
79+
80+ for (int i = 0; i < programcount; i++) {
81+ if (
82+ x >= programs[i].x &&
83+ x <= programs[i].x + programs[i].width &&
84+ y >= programs[i].y - item_height &&
85+ y <= programs[i].y
86+ ) {
87+ launch_program(programs[i].exec, programs[i].term);
88+ break;
89+ }
90+ }
91+}
追加 src/control.h
@@ -0,0 +1,12 @@
1+#ifndef CONTROL_H
2+#define CONTROL_H
3+
4+#include "program.h"
5+
6+void control_expose(
7+ Display *display, Window window, GC gc, XEvent *event, char *input, int *sel);
8+void control_keypress(
9+ Display *display, Window window, GC gc, XEvent *event, char *input, int *sel);
10+void control_buttonpress(XEvent *event, Program *programs, int item_height);
11+
12+#endif
追加 src/display.c
@@ -0,0 +1,46 @@
1+#include "display.h"
2+
3+#include <string.h>
4+
5+int topidx = 0;
6+
7+void drawtext(
8+ Display *display, Window window, GC gc, int x, int y, const char *text, int sel) {
9+ if (sel) {
10+ XSetForeground(display, gc, BLACK);
11+ XFillRectangle(
12+ display, window, gc, 0, y - item_height + 5, window_width, item_height);
13+ XSetForeground(display, gc, BLACK);
14+ } else {
15+ XSetForeground(display, gc, WHITE);
16+ }
17+
18+ XftDrawStringUtf8(draw, &color, font, x, y, (const FcChar8 *)text, strlen(text));
19+}
20+
21+void filterdisplay(
22+ Display *display,
23+ Window window,
24+ GC gc,
25+ const char *input,
26+ int sel
27+) {
28+ XClearWindow(display, window);
29+
30+ // 検索ボックス
31+ drawtext(display, window, gc, 10, item_height, input, 0);
32+
33+ int y = item_height * 2;
34+ int idx = 0;
35+
36+ for (int i = 0; i < programcount; i++) {
37+ if (!strcasestr(programs[i].name, input) && !strcasestr(programs[i].keys, input))
38+ continue;
39+
40+ if (idx >= topidx && idx < topidx + display_items) {
41+ drawtext(display, window, gc, 10, y, programs[i].name, idx == sel);
42+ y += item_height;
43+ }
44+ idx++;
45+ }
46+}
追加 src/display.h
@@ -0,0 +1,21 @@
1+#ifndef DISPLAY_H
2+#define DISPLAY_H
3+
4+#include "program.h"
5+
6+#include <X11/Xlib.h>
7+#include <X11/Xft/Xft.h>
8+
9+void drawtext(
10+ Display *display, Window window, GC gc, int x, int y, const char *text, int sel);
11+void filterdisplay(
12+ Display *display, Window window, GC gc, const char *input, int sel);
13+
14+extern XftColor color, selcolor;
15+extern Colormap colormap;
16+extern XftDraw *draw;
17+extern XftFont *font;
18+extern Visual *visual;
19+extern int topidx;
20+
21+#endif
追加 src/parser.c
@@ -0,0 +1,138 @@
1+#include "parser.h"
2+#include "utils.h"
3+
4+#include <stdio.h>
5+#include <string.h>
6+#include <stdbool.h>
7+#include <stdlib.h>
8+#include <dirent.h>
9+#include <unistd.h>
10+
11+bool foundName = false;
12+bool foundKey = false;
13+bool foundExec = false;
14+bool isDesktopEntry = false;
15+
16+void parse_name(char *line, Program *program) {
17+ if (foundName) return;
18+ if (strncmp(line, "Name[", 5) == 0) {
19+ char *locale = line + 5;
20+ char *end = strchr(locale, ']');
21+ if (!end) return;
22+ *end = '\0';
23+ if (strncmp(locale, getenv("LANG"), 2) != 0) return;
24+ if (!isdup(end + 2)) {
25+ strncpy(program->name, end + 2, MAX_NAME_LEN - 1);
26+ program->name[strcspn(program->name, "\n")] = '\0';
27+ }
28+ add_to_dup(end + 2);
29+ foundName = true;
30+ } else {
31+ if (!isdup(line + 5)) {
32+ strncpy(program->name, line + 5, MAX_NAME_LEN - 1);
33+ program->name[strcspn(program->name, "\n")] = '\0';
34+ }
35+ add_to_dup(line + 5);
36+ foundName = true;
37+ }
38+}
39+
40+void parse_keywords(char *line, Program *program) {
41+ if (foundKey) return;
42+ size_t len = strnlen(line + 9, MAX_NAME_LEN - 1);
43+ strncpy(program->keys, line + 9, len);
44+ program->keys[len] = '\0';
45+
46+ program->keys[strcspn(program->keys, "\n")] = '\0';
47+ foundKey = true;
48+}
49+
50+void parse_exec(char *line, Program *program) {
51+ if (foundExec) return;
52+ size_t len = strnlen(line + 5, MAX_NAME_LEN - 1);
53+ strncpy(program->exec, line + 5, len);
54+ program->exec[strcspn(program->exec, "\n")] = '\0';
55+
56+ char *p = program->exec;
57+ while ((p = strpbrk(p, "%")) != NULL) {
58+ *p = '\0';
59+
60+ size_t rspace = MAX_NAME_LEN - strlen(program->exec) - 1;
61+ if (rspace > 0) {
62+ strncat(program->exec, p + 2, rspace);
63+ }
64+ }
65+ foundExec = true;
66+}
67+
68+void parse_term(char *line, Program *program) {
69+ size_t len = strnlen(line + 9, MAX_NAME_LEN - 1);
70+ strncpy(program->term, line + 9, len);
71+ program->term[strcspn(program->term, "\n")] = '\0';
72+
73+ char *p = program->term;
74+
75+ while ((p = strpbrk(p, "%")) != NULL) {
76+ *p = '\0';
77+
78+ size_t rspace = MAX_NAME_LEN - strlen(program->term) - 1;
79+ if (rspace > 0) {
80+ strncat(program->term, p + 2, rspace);
81+ }
82+ }
83+}
84+
85+void parse_desktop_file(const char *filepath) {
86+ FILE *file = fopen(filepath, "r");
87+ if (!file) return;
88+
89+ char line[MAX_NAME_LEN * 2];
90+ Program program = {0};
91+
92+ while (fgets(line, sizeof(line), file)) {
93+ if (strncmp(line, "Name=", 5) == 0 || strncmp(line, "Name[", 5) == 0) {
94+ parse_name(line, &program);
95+ } else if (strncmp(line, "Keywords=", 9) == 0) {
96+ parse_keywords(line, &program);
97+ } else if (strncmp(line, "Exec=", 5) == 0) {
98+ parse_exec(line, &program);
99+ } else if (strncmp(line, "Terminal=", 9) == 0) {
100+ parse_term(line, &program);
101+ }
102+ }
103+
104+ fclose(file);
105+
106+ if (program.name[0] && program.exec[0]) {
107+ programs[programcount++] = program;
108+ }
109+}
110+
111+void scan_desktop_files(const char *directory) {
112+ DIR *dir = opendir(directory);
113+ if (!dir) return;
114+
115+ struct dirent *entry;
116+ while ((entry = readdir(dir)) != NULL) {
117+ if (strcasestr(entry->d_name, ".desktop")) {
118+ size_t filepath_len = strlen(directory) + strlen(entry->d_name) + 2;
119+ char *filepath = malloc(filepath_len);
120+ if (!filepath) {
121+ closedir(dir);
122+ return;
123+ }
124+
125+ snprintf(filepath, filepath_len, "%s/%s", directory, entry->d_name);
126+ if (isdis(filepath)) parse_desktop_file(filepath);
127+
128+ isDesktopEntry = false;
129+ foundName = false;
130+ foundKey = false;
131+ foundExec = false;
132+
133+ free(filepath);
134+ }
135+ }
136+
137+ closedir(dir);
138+}
追加 src/parser.h
@@ -0,0 +1,13 @@
1+#ifndef PARSER_H
2+#define PARSER_H
3+
4+#include "program.h"
5+
6+void parse_name(char *line, Program *program);
7+void parse_keywords(char *line, Program *program);
8+void parse_exec(char *line, Program *program);
9+void parse_term(char *line, Program *program);
10+void parse_desktop_file(const char *filepath);
11+void scan_desktop_files(const char *directory);
12+
13+#endif
追加 src/program.c
@@ -0,0 +1,70 @@
1+#include "program.h"
2+#include "parser.h"
3+
4+#include <X11/Xlib.h>
5+#include <X11/Xft/Xft.h>
6+
7+#include <stdio.h>
8+#include <stdlib.h>
9+#include <unistd.h>
10+#include <string.h>
11+
12+Program programs[MAX_ITEMS];
13+int programcount = 0;
14+int window_width = 300;
15+int window_height = 240;
16+int item_height = 20;
17+int display_items = 10;
18+
19+void fetch_programs() {
20+ char *xdg_data_home = getenv("XDG_DATA_HOME");
21+ if (!xdg_data_home) {
22+ xdg_data_home = getenv("HOME");
23+ if (xdg_data_home) {
24+ char path[MAX_NAME_LEN];
25+ snprintf(path, sizeof(path), "%s/.local/share/applications", xdg_data_home);
26+ scan_desktop_files(path);
27+ }
28+ } else {
29+ char path[MAX_NAME_LEN];
30+ snprintf(path, sizeof(path), "%s/applications", xdg_data_home);
31+ scan_desktop_files(path);
32+ }
33+
34+ scan_desktop_files("/usr/share/applications");
35+ scan_desktop_files("/usr/local/share/applications");
36+#if defined(__NetBSD__)
37+ scan_desktop_files("/usr/pkg/share/applications");
38+#endif
39+}
40+
41+void launch_program(const char *exec, const char *term) {
42+ if (fork() == 0) {
43+ setsid();
44+ if (strncmp(term, "true", 4) == 0) {
45+ char *terminal = getenv("TERMINAL");
46+ if (!terminal) terminal = "xterm";
47+ execlp(terminal, terminal, "-e", exec, NULL);
48+ } else {
49+ execl("/bin/sh", "sh", "-c", exec, NULL);
50+ }
51+ exit(0);
52+ }
53+}
54+
55+int filtercount(const char *input) {
56+ int count = 0;
57+
58+ for (int i = 0; i < programcount; i++) {
59+ if (strcasestr(programs[i].name, input) || strcasestr(programs[i].keys, input))
60+ count++;
61+ }
62+
63+ return count;
64+}
65+
66+void calculate_dimensions(int win_width, int win_height) {
67+ window_width = win_width;
68+ window_height = win_height;
69+ item_height = win_height / (display_items + 2);
70+}
追加 src/program.h
@@ -0,0 +1,35 @@
1+#ifndef PROGRAM_H
2+#define PROGRAM_H
3+
4+#include <X11/Xlib.h>
5+#include <X11/Xft/Xft.h>
6+
7+#define MAX_ITEMS 512
8+#define MAX_NAME_LEN 256
9+#define MAX_LINE_LENGTH 256
10+
11+#define WHITE 0xfcfcfc
12+#define BLACK 0x120f12
13+#define BGCOL 0x550f75
14+
15+typedef struct {
16+ char name[MAX_NAME_LEN];
17+ char keys[MAX_NAME_LEN];
18+ char exec[MAX_NAME_LEN];
19+ char term[MAX_NAME_LEN];
20+ int x, y, width, height;
21+} Program;
22+
23+void fetch_programs();
24+void launch_program(const char *exec, const char *term);
25+int filtercount(const char *input);
26+void calculate_dimensions(int win_width, int win_height);
27+
28+extern Program programs[MAX_ITEMS];
29+extern int programcount;
30+extern int window_width;
31+extern int window_height;
32+extern int item_height;
33+extern int display_items;
34+
35+#endif
追加 src/utils.c
@@ -0,0 +1,98 @@
1+#include "utils.h"
2+
3+#include <string.h>
4+#include <stdio.h>
5+#include <stdlib.h>
6+#include <unistd.h>
7+
8+#if defined(__linux__)
9+#include <string.h>
10+#include <ctype.h>
11+#endif
12+
13+Dup dupn[MAX_NAME_LEN * 2];
14+int dupcnt = 0;
15+
16+#if defined(__linux__)
17+#include <string.h>
18+
19+char *strcasestr(const char *haystack, const char *needle) {
20+ size_t needle_len = strlen(needle);
21+ if (needle_len == 0) {
22+ return (char *)haystack;
23+ }
24+
25+ while (*haystack) {
26+ if (strncasecmp(haystack, needle, needle_len) == 0) {
27+ return (char *)haystack;
28+ }
29+ haystack++;
30+ }
31+ return NULL;
32+}
33+#endif
34+
35+int isdup(const char *name) {
36+ for (int i = 0; i < dupcnt; i++) {
37+ if (strncmp(dupn[i].name, name, strlen(name)) == 0) return 1;
38+ }
39+
40+ return 0;
41+}
42+
43+int isdis(const char *filepath) {
44+ FILE *file = fopen(filepath, "r");
45+ if (!file) return 0;
46+
47+ char line[MAX_LINE_LENGTH];
48+ while (fgets(line, sizeof(line), file)) {
49+ if (strstr(line, "NoDisplay=true")) {
50+ fclose(file);
51+ return 0;
52+ }
53+ }
54+
55+ fclose(file);
56+ return 1;
57+}
58+
59+void add_to_dup(const char *name) {
60+ if (dupcnt < (MAX_NAME_LEN * 2)) {
61+ strncpy(dupn[dupcnt].name, name, MAX_NAME_LEN - 1);
62+ dupn[dupcnt].name[MAX_NAME_LEN - 1] = '\0';
63+ dupcnt++;
64+ }
65+}
66+
67+int launch_path(const char *exec) {
68+ char *path = getenv("PATH");
69+ if (!path) return 1;
70+
71+ char *pdup = strdup(path);
72+ char *dir = strtok(pdup, ":");
73+ while (dir != NULL) {
74+ char fp[1024];
75+ snprintf(fp, sizeof(fp), "%s/%s", dir, exec);
76+
77+ if (access(fp, X_OK) == 0) {
78+ free(pdup);
79+ return 1;
80+ }
81+ dir = strtok(NULL, ":");
82+ }
83+
84+ free(pdup);
85+ return 0;
86+}
87+
88+void cleanup(Display *display, Window window, GC gc, XftColor *color,
89+ XftColor *selcolor, XftDraw *draw, XftFont *font,
90+ Colormap colormap, Visual *visual) {
91+ if (color) XftColorFree(display, visual, colormap, color);
92+ if (selcolor) XftColorFree(display, visual, colormap, selcolor);
93+ if (font) XftFontClose(display, font);
94+ if (draw) XftDrawDestroy(draw);
95+ if (gc) XFreeGC(display, gc);
96+ if (window) XDestroyWindow(display, window);
97+ if (display) XCloseDisplay(display);
98+}
追加 src/utils.h
@@ -0,0 +1,28 @@
1+#ifndef UTILS_H
2+#define UTILS_H
3+
4+#include "program.h"
5+
6+#include <X11/Xlib.h>
7+#include <X11/Xft/Xft.h>
8+
9+typedef struct {
10+ char name[MAX_NAME_LEN];
11+} Dup;
12+
13+extern Dup dupn[MAX_NAME_LEN * 2];
14+extern int dupcnt;
15+
16+#if defined(__linux__)
17+char *strcasestr(const char *haystack, const char *needle);
18+#endif
19+
20+int isdup(const char *name);
21+int isdis(const char *filepath);
22+void add_to_dup(const char *name);
23+int launch_path(const char *exec);
24+void cleanup(Display *display, Window window, GC gc,
25+ XftColor *color, XftColor *selcolor, XftDraw *draw, XftFont *font,
26+ Colormap colormap, Visual *visual);
27+
28+#endif
追加 um.desktop
@@ -0,0 +1,10 @@
1+[Desktop Entry]
2+Type=Application
3+Name=um
4+GenericName=Just launcher
5+GenericName[ja]=只のラウンチャー
6+Exec=um %F
7+StartupNotify=true
8+Terminal=false
9+Type=Application
10+Categories=Application;Utility;System;DeskopUtility;