History

fix ui

~Not Toby committed 6 months ago

Commit 8dd20891 parent 51947812 files · +59 −131Browse files

Unified · Split

2 files
  1. 9x.c +52 −123
  2. config.h +7 −8
9x.c+52−123
@@ -1,3 +1,4 @@
1/* 9x - Plan 9 style window manager. BSD-3-Clause. */
1#include <ctype.h>2#include <ctype.h>
2#include <dirent.h>3#include <dirent.h>
3#include <err.h>4#include <err.h>
@@ -117,62 +118,38 @@ enum { Pdelete = 1, Ptakefocus = 2 }; · 113 unmodified lines
117static Display *dpy;118static Display *dpy;
118static int screen;119static int screen;
119static Window root;120static Window root;
120static unsigned int sw, sh;121static unsigned int sw, sh, barw, barh;
121static XftFont *xftfont;122static XftFont *xftfont;
122static Cursor c_arrow, c_sweep, c_box;123static Cursor c_arrow, c_sweep, c_box, c_border[NBorder];
123static Cursor c_border[NBorder];
124static Atom wm_protocols, wm_delete, wm_take_focus, wm_state;124static Atom wm_protocols, wm_delete, wm_take_focus, wm_state;
125static Atom net_supported, net_supporting, net_client_list, net_active;125static Atom net_supported, net_supporting, net_client_list, net_active;
126static Atom net_num_desks, net_cur_desk, net_wm_desk, net_workarea;126static Atom net_num_desks, net_cur_desk, net_wm_desk, net_workarea;
127static Atom net_wm_name, net_wm_state, net_wm_state_fs, net_frame_ext;127static Atom net_wm_name, net_wm_state, net_wm_state_fs, net_frame_ext;
128static Atom net_wm_type, net_wm_type_dock;128static Atom net_wm_type, net_wm_type_dock, utf8_string;
129static Atom utf8_string;129static Client *clients, *current;
130static Client *clients;130static unsigned long col_active, col_inactive, col_red;
131static Client *current;
132static unsigned long col_active, col_inactive;
133static unsigned long col_red;
134static volatile sig_atomic_t running = 1;131static volatile sig_atomic_t running = 1;
135static Window swout[4];132static Window swout[4], wmcheck, barwin, last_click_win;
136static Window wmcheck;133static time_t sweep_pending, bar_deadline;
137static time_t sweep_pending;134static int sweep_x, sweep_y, curdesk, bar_batt = -1, bar_onac;
138static int sweep_x, sweep_y;
139static unsigned int sweep_dx, sweep_dy;135static unsigned int sweep_dx, sweep_dy;
140static Time last_click_time;136static Time last_click_time;
141static Window last_click_win;
142static int curdesk;
143static Client *deskfocus[NDESKS];137static Client *deskfocus[NDESKS];
144static Window barwin;
145static Pixmap barpix;138static Pixmap barpix;
146static GC bargc;139static GC bargc;
147static XftDraw *bardraw;140static XftDraw *bardraw;
148static XftColor bar_fg, bar_bg, bar_sel, bar_self, bar_tab;141static XftColor bar_fg, bar_bg, bar_sel, bar_self, bar_tab;
149static XftColor bar_run, bar_exit, bar_desk[DESK_COLORS];142static XftColor bar_run, bar_exit, bar_desk[DESK_COLORS];
150static unsigned long col_bar_bd;
151static unsigned int barw, barh;
152static int bar_batt = -1;
153static int bar_onac;
154static time_t bar_deadline;
155 143
156static Client *bar_tabs[MAXCLIENTS];144static Client *bar_tabs[MAXCLIENTS];
157static int bar_tab_x[MAXCLIENTS];145static int bar_tab_x[MAXCLIENTS], bar_tab_w[MAXCLIENTS], bar_ntabs;
158static int bar_tab_w[MAXCLIENTS];146static int bar_run_x, bar_run_w, bar_desk_w, bar_status_x, bar_exit_x, bar_exit_w;
159static int bar_ntabs;147static int bar_desk_x[NDESKS];
160 148static int launch_visible, launch_ncmds, launch_sel = -1, launch_scroll;
161static int bar_run_x, bar_run_w;149static int launch_filterlen, launch_nfiltered, launch_nitems;
162static int bar_desk_x[NDESKS], bar_desk_w;
163static int bar_status_x;
164static int bar_exit_x, bar_exit_w;
165static int launch_visible;
166static char *launch_cmds[MAXCMDS];150static char *launch_cmds[MAXCMDS];
167static int launch_ncmds;
168static int launch_sel = -1;
169static int launch_scroll;
170static char launch_filter[256];151static char launch_filter[256];
171static int launch_filterlen;152static int launch_filtered[MAXCMDS], launch_item_x[MAXCMDS], launch_item_w[MAXCMDS];
172static int launch_filtered[MAXCMDS];
173static int launch_nfiltered;
174static int launch_item_x[MAXCMDS];
175static int launch_item_w[MAXCMDS];
176static int launch_nitems;153static int launch_nitems;
177static void bar_redraw(void);154static void bar_redraw(void);
178 155
@@ -186,29 +163,16 @@ raisebar(void) · 7 unmodified lines
186static unsigned long163static unsigned long
187getcolor(unsigned long rgb)164getcolor(unsigned long rgb)
188{165{
189 XColor c;166 XColor c = {0, RGB16(rgb >> 16), RGB16(rgb >> 8), RGB16(rgb), DoRed | DoGreen | DoBlue, 0};
190 167 return XAllocColor(dpy, DefaultColormap(dpy, screen), &c) ? c.pixel : WhitePixel(dpy, screen);
191 c.red = RGB16(rgb >> 16);
192 c.green = RGB16(rgb >> 8);
193 c.blue = RGB16(rgb);
194 c.flags = DoRed | DoGreen | DoBlue;
195 if(!XAllocColor(dpy, DefaultColormap(dpy, screen), &c))
196 return WhitePixel(dpy, screen);
197 return c.pixel;
198}168}
199 169
200static XftColor170static XftColor
201getxftcolor(unsigned long rgb)171getxftcolor(unsigned long rgb)
202{172{
203 XRenderColor rc;173 XRenderColor rc = {RGB16(rgb >> 16), RGB16(rgb >> 8), RGB16(rgb), 0xFFFF};
204 XftColor c = {0};174 XftColor c = {0};
205 175 if(!XftColorAllocValue(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &rc, &c))
206 rc.red = RGB16(rgb >> 16);
207 rc.green = RGB16(rgb >> 8);
208 rc.blue = RGB16(rgb);
209 rc.alpha = 0xFFFF;
210 if(!XftColorAllocValue(dpy, DefaultVisual(dpy, screen),
211 DefaultColormap(dpy, screen), &rc, &c))
212 c.pixel = WhitePixel(dpy, screen);176 c.pixel = WhitePixel(dpy, screen);
213 return c;177 return c;
214}178}
@@ -216,20 +180,12 @@ getxftcolor(unsigned long rgb) · 1 unmodified line
216static Cursor180static Cursor
217makecursor(Cursordata *d)181makecursor(Cursordata *d)
218{182{
219 Pixmap f, m;
220 Cursor cur;
221 XColor bl, wh, dummy;183 XColor bl, wh, dummy;
222 184 XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &bl, &dummy);
223 XAllocNamedColor(dpy, DefaultColormap(dpy, screen),185 XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "white", &wh, &dummy);
224 "black", &bl, &dummy);186 Pixmap f = XCreatePixmapFromBitmapData(dpy, root, (char *)d->fore, d->width, d->width, 1, 0, 1);
225 XAllocNamedColor(dpy, DefaultColormap(dpy, screen),187 Pixmap m = XCreatePixmapFromBitmapData(dpy, root, (char *)d->mask, d->width, d->width, 1, 0, 1);
226 "white", &wh, &dummy);188 Cursor cur = XCreatePixmapCursor(dpy, f, m, &bl, &wh, d->hot[0], d->hot[1]);
227 f = XCreatePixmapFromBitmapData(dpy, root, (char *)d->fore,
228 d->width, d->width, 1, 0, 1);
229 m = XCreatePixmapFromBitmapData(dpy, root, (char *)d->mask,
230 d->width, d->width, 1, 0, 1);
231 cur = XCreatePixmapCursor(dpy, f, m, &bl, &wh,
232 d->hot[0], d->hot[1]);
233 XFreePixmap(dpy, f);189 XFreePixmap(dpy, f);
234 XFreePixmap(dpy, m);190 XFreePixmap(dpy, m);
235 return cur;191 return cur;
@@ -239,41 +195,19 @@ static int · 3 unmodified lines
239xft_textwidth(const char *s, int len)195xft_textwidth(const char *s, int len)
240{196{
241 XGlyphInfo ext;197 XGlyphInfo ext;
242
243 XftTextExtentsUtf8(dpy, xftfont, (const FcChar8 *)s, len, &ext);198 XftTextExtentsUtf8(dpy, xftfont, (const FcChar8 *)s, len, &ext);
244 return ext.xOff;199 return ext.xOff;
245}200}
246 201
247static int202static int handler(Display *d, XErrorEvent *e) { USED(d); USED(e); return 0; }
248handler(Display *d, XErrorEvent *e)203static void sigchld(int sig) { USED(sig); while(waitpid(-1, NULL, WNOHANG) > 0); }
249{204static void sigterm(int sig) { USED(sig); running = 0; }
250 USED(d); USED(e);
251 return 0;
252}
253
254static void
255sigchld(int sig)
256{
257 USED(sig);
258 while(waitpid(-1, NULL, WNOHANG) > 0)
259 ;
260}
261
262static void
263sigterm(int sig)
264{
265 USED(sig);
266 running = 0;
267}
268 205
269static void206static void
270spawn(const char *cmd)207spawn(const char *cmd)
271{208{
272 pid_t p;209 pid_t p = fork();
273 210 if(p < 0) return;
274 p = fork();
275 if(p < 0)
276 return;
277 if(p == 0){211 if(p == 0){
278 if(fork() == 0){212 if(fork() == 0){
279 setsid();213 setsid();
@@ -435,8 +369,6 @@ bar_drawbtn(int x, int w, const char *s, int len, int sel, XftColor *bg) · 155 unmodified lines
435 if(w <= 0)369 if(w <= 0)
436 return;370 return;
437 XftDrawRect(bardraw, sel ? &bar_sel : bg, x, 0, (unsigned int)w, barh);371 XftDrawRect(bardraw, sel ? &bar_sel : bg, x, 0, (unsigned int)w, barh);
438 XSetForeground(dpy, bargc, col_bar_bd);
439 XDrawRectangle(dpy, barpix, bargc, x, 0, (unsigned int)(w - 1), barh - 1);
440 XftDrawStringUtf8(bardraw, sel ? &bar_self : &bar_fg, xftfont,372 XftDrawStringUtf8(bardraw, sel ? &bar_self : &bar_fg, xftfont,
441 x + BAR_BTN_PAD, ty, (const FcChar8 *)s, len);373 x + BAR_BTN_PAD, ty, (const FcChar8 *)s, len);
442}374}
@@ -455,8 +387,6 @@ launcher_draw(void) · 12 unmodified lines
455 x = BAR_GAP;387 x = BAR_GAP;
456 388
457 XftDrawRect(bardraw, &bar_tab, x, 0, LAUNCH_FILTER_W, barh);389 XftDrawRect(bardraw, &bar_tab, x, 0, LAUNCH_FILTER_W, barh);
458 XSetForeground(dpy, bargc, col_bar_bd);
459 XDrawRectangle(dpy, barpix, bargc, x, 0, LAUNCH_FILTER_W - 1, barh - 1);
460 XftDrawStringUtf8(bardraw, &bar_fg, xftfont,390 XftDrawStringUtf8(bardraw, &bar_fg, xftfont,
461 x + BAR_BTN_PAD, ty, (const FcChar8 *)launch_filter, launch_filterlen);391 x + BAR_BTN_PAD, ty, (const FcChar8 *)launch_filter, launch_filterlen);
462 XftTextExtentsUtf8(dpy, xftfont, (const FcChar8 *)launch_filter, launch_filterlen, &ext);392 XftTextExtentsUtf8(dpy, xftfont, (const FcChar8 *)launch_filter, launch_filterlen, &ext);
@@ -483,8 +413,6 @@ launcher_draw(void) · 20 unmodified lines
483 XftDrawRect(bardraw, sel ? &bar_sel : &bar_tab, x, 0, (unsigned int)tw, barh);413 XftDrawRect(bardraw, sel ? &bar_sel : &bar_tab, x, 0, (unsigned int)tw, barh);
484 XftDrawStringUtf8(bardraw, sel ? &bar_self : &bar_fg, xftfont,414 XftDrawStringUtf8(bardraw, sel ? &bar_self : &bar_fg, xftfont,
485 x + BAR_BTN_PAD, ty, (const FcChar8 *)name, nlen);415 x + BAR_BTN_PAD, ty, (const FcChar8 *)name, nlen);
486 XSetForeground(dpy, bargc, col_bar_bd);
487 XDrawRectangle(dpy, barpix, bargc, x, 0, (unsigned int)(tw - 1), barh - 1);
488 x += tw + BAR_GAP;416 x += tw + BAR_GAP;
489 }417 }
490 418
@@ -680,9 +608,6 @@ bar_drawtabs(int x, int tabarea, int rightw) · 189 unmodified lines
680 tabx, 0, (unsigned int)tw, barh);608 tabx, 0, (unsigned int)tw, barh);
681 XftDrawStringUtf8(bardraw, sel ? &bar_self : &bar_fg, xftfont,609 XftDrawStringUtf8(bardraw, sel ? &bar_self : &bar_fg, xftfont,
682 tabx + BAR_BTN_PAD, ty, (const FcChar8 *)name, nlen);610 tabx + BAR_BTN_PAD, ty, (const FcChar8 *)name, nlen);
683 XSetForeground(dpy, bargc, col_bar_bd);
684 XDrawRectangle(dpy, barpix, bargc, tabx, 0,
685 (unsigned int)(tw - 1), barh - 1);
686 tabx += tw + BAR_GAP;611 tabx += tw + BAR_GAP;
687 }612 }
688 bar_ntabs = drawn;613 bar_ntabs = drawn;
@@ -1007,6 +932,16 @@ applylayout(Client *c) · 318 unmodified lines
1007 sendconfig(c);932 sendconfig(c);
1008}933}
1009 934
935static Client *
936topclient(void)
937{
938 Client *c;
939 for(c = clients; c; c = c->next)
940 if(c->virt == curdesk)
941 return c;
942 return NULL;
943}
944
1010static void945static void
1011switch_to(int n)946switch_to(int n)
1012{947{
@@ -1025,19 +960,13 @@ switch_to(int n) · 12 unmodified lines
1025static void960static void
1026sendtodesktop(Client *c, int n)961sendtodesktop(Client *c, int n)
1027{962{
1028 Client *next;
1029
1030 if(!c || n < 0 || n >= NDESKS || n == curdesk)963 if(!c || n < 0 || n >= NDESKS || n == curdesk)
1031 return;964 return;
1032 c->virt = n;965 c->virt = n;
1033 ewmh_set(c->win, net_wm_desk, XA_CARDINAL, 32, &(long){n}, 1);966 ewmh_set(c->win, net_wm_desk, XA_CARDINAL, 32, &(long){n}, 1);
1034 XUnmapWindow(dpy, c->frame);967 XUnmapWindow(dpy, c->frame);
1035 if(current == c){968 if(current == c)
1036 for(next = clients; next; next = next->next)969 focus(topclient());
1037 if(next->virt == curdesk)
1038 break;
1039 focus(next);
1040 }
1041 deskfocus[n] = c;970 deskfocus[n] = c;
1042 switch_to(n);971 switch_to(n);
1043}972}
@@ -1190,10 +1119,7 @@ unmanage(Client *c) · 146 unmodified lines
1190 ewmh_updateclients();1119 ewmh_updateclients();
1191 if(current == c){1120 if(current == c){
1192 current = NULL;1121 current = NULL;
1193 for(c = clients; c; c = c->next)1122 focus(topclient());
1194 if(c->virt == curdesk)
1195 break;
1196 focus(c);
1197 } else1123 } else
1198 bar_redraw();1124 bar_redraw();
1199 free(old->label);1125 free(old->label);
@@ -1604,10 +1530,7 @@ buttonpress(XButtonEvent *e) · 404 unmodified lines
1604 XUnmapWindow(dpy, current->frame);1530 XUnmapWindow(dpy, current->frame);
1605 deskfocus[i] = current;1531 deskfocus[i] = current;
1606 ewmh_updateclients();1532 ewmh_updateclients();
1607 for(c = clients; c; c = c->next)1533 focus(topclient());
1608 if(c->virt == curdesk)
1609 break;
1610 focus(c);
1611 } else if(btn == Button3)1534 } else if(btn == Button3)
1612 sendtodesktop(current, i);1535 sendtodesktop(current, i);
1613 return;1536 return;
@@ -1787,7 +1710,6 @@ static void · 173 unmodified lines
1787clientmessage(XClientMessageEvent *e)1710clientmessage(XClientMessageEvent *e)
1788{1711{
1789 Client *c;1712 Client *c;
1790 int fs;
1791 1713
1792 if(e->message_type == net_cur_desk){1714 if(e->message_type == net_cur_desk){
1793 if(e->data.l[0] >= 0 && e->data.l[0] < NDESKS)1715 if(e->data.l[0] >= 0 && e->data.l[0] < NDESKS)
@@ -1802,6 +1724,7 @@ clientmessage(XClientMessageEvent *e) · 8 unmodified lines
1802 switch_to(c->virt);1724 switch_to(c->virt);
1803 focus(c);1725 focus(c);
1804 } else if(e->message_type == net_wm_state){1726 } else if(e->message_type == net_wm_state){
1727 int fs;
1805 if((Atom)e->data.l[1] != net_wm_state_fs && (Atom)e->data.l[2] != net_wm_state_fs)1728 if((Atom)e->data.l[1] != net_wm_state_fs && (Atom)e->data.l[2] != net_wm_state_fs)
1806 return;1729 return;
1807 fs = e->data.l[0] == 1 || (e->data.l[0] == 2 && !c->fullscreen);1730 fs = e->data.l[0] == 1 || (e->data.l[0] == 2 && !c->fullscreen);
@@ -1809,8 +1732,15 @@ clientmessage(XClientMessageEvent *e) · 1 unmodified line
1809 return;1732 return;
1810 if(fs) savegeom(c);1733 if(fs) savegeom(c);
1811 c->fullscreen = fs;1734 c->fullscreen = fs;
1735 if(fs){
1736 ewmh_set(c->win, net_wm_state, XA_ATOM, 32, &net_wm_state_fs, 1);
1737 ewmh_set(c->win, net_frame_ext, XA_CARDINAL, 32, (long[]){0,0,0,0}, 4);
1738 } else {
1739 XDeleteProperty(dpy, c->win, net_wm_state);
1740 ewmh_set(c->win, net_frame_ext, XA_CARDINAL, 32, (long[]){BORDER,BORDER,BORDER,BORDER}, 4);
1741 }
1812 applylayout(c);1742 applylayout(c);
1813 fs ? XRaiseWindow(dpy, c->frame) : raisebar();1743 focus(c);
1814 }1744 }
1815}1745}
1816 1746
@@ -1846,7 +1776,6 @@ setup_bar(void) · 29 unmodified lines
1846 bar_desk[1] = getxftcolor(COL_BAR_DESK1);1776 bar_desk[1] = getxftcolor(COL_BAR_DESK1);
1847 bar_desk[2] = getxftcolor(COL_BAR_DESK2);1777 bar_desk[2] = getxftcolor(COL_BAR_DESK2);
1848 bar_desk[3] = getxftcolor(COL_BAR_DESK3);1778 bar_desk[3] = getxftcolor(COL_BAR_DESK3);
1849 col_bar_bd = getcolor(COL_BAR_BD);
1850 1779
1851 barw = sw;1780 barw = sw;
1852 barh = (unsigned int)(xftfont->ascent + xftfont->descent) + BAR_PAD * 2;1781 barh = (unsigned int)(xftfont->ascent + xftfont->descent) + BAR_PAD * 2;
config.h+7−8
@@ -1,16 +1,15 @@
1/* Colors - Plan 9 palette */1/* Colors - Plan 9 palette */
2#define COL_ACTIVE 0x55AAAA /* active border - dark cyan */2#define COL_ACTIVE 0x55AAAA /* active border - teal */
3#define COL_INACTIVE 0x9EEEEE /* inactive border - pale cyan */3#define COL_INACTIVE 0x9EEEEE /* inactive border - pale cyan */
4#define COL_SWEEP_BD 0xDD0000 /* sweep outline - red */4#define COL_SWEEP_BD 0xAA0000 /* sweep outline - red */
5#define COL_ROOT_BG 0x777777 /* root background - grey */5#define COL_ROOT_BG 0x999999 /* root background - grey */
6 6
7/* Bar colors */7/* Bar colors */
8#define COL_BAR_BG 0xEAFFFF /* background - pale cyan */8#define COL_BAR_BG 0xEAFFFF /* background - pale cyan */
9#define COL_BAR_FG 0x000000 /* text - black */9#define COL_BAR_FG 0x000000 /* text - black */
10#define COL_BAR_SEL 0x9EEEEE /* selection - pale blue */10#define COL_BAR_SEL 0x55AAAA /* selection - teal */
11#define COL_BAR_SELF 0x005555 /* selection text - dark teal */11#define COL_BAR_SELF 0xFFFFFF /* selection text - white */
12#define COL_BAR_TAB 0xEEFFEE /* tab - pale green */12#define COL_BAR_TAB 0xEEFFEE /* tab - pale green */
13#define COL_BAR_BD 0x88AAAA /* border - muted cyan */
14#define COL_BAR_RUN 0x99EE99 /* run button - green */13#define COL_BAR_RUN 0x99EE99 /* run button - green */
15#define COL_BAR_EXIT 0xEE9999 /* exit button - red */14#define COL_BAR_EXIT 0xEE9999 /* exit button - red */
16#define COL_BAR_DESK0 0xEAFFEA /* desk empty */15#define COL_BAR_DESK0 0xEAFFEA /* desk empty */
@@ -20,11 +19,11 @@ · 3 unmodified lines
20 19
21/* Geometry */20/* Geometry */
22#define BORDER 421#define BORDER 4
23#define CORNER 2522#define CORNER 32
24 23
25/* Bar */24/* Bar */
26#define BAR_PAD 225#define BAR_PAD 2
27#define BAR_BTN_PAD 426#define BAR_BTN_PAD 2
28#define BAR_GAP 227#define BAR_GAP 2
29#define BAR_REFRESH 6028#define BAR_REFRESH 60
30#define LAUNCH_FILTER_W 20029#define LAUNCH_FILTER_W 200

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t