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. */
12 #include <ctype.h>
23 #include <dirent.h>
34 #include <err.h>
@@ -117,62 +118,38 @@ enum { Pdelete = 1, Ptakefocus = 2 }; · 113 unmodified lines
117118 static Display *dpy;
118119 static int screen;
119120 static Window root;
120−static unsigned int sw, sh;
121+static unsigned int sw, sh, barw, barh;
121122 static XftFont *xftfont;
122−static Cursor c_arrow, c_sweep, c_box;
123−static Cursor c_border[NBorder];
123+static Cursor c_arrow, c_sweep, c_box, c_border[NBorder];
124124 static Atom wm_protocols, wm_delete, wm_take_focus, wm_state;
125125 static Atom net_supported, net_supporting, net_client_list, net_active;
126126 static Atom net_num_desks, net_cur_desk, net_wm_desk, net_workarea;
127127 static Atom net_wm_name, net_wm_state, net_wm_state_fs, net_frame_ext;
128−static Atom net_wm_type, net_wm_type_dock;
129−static Atom utf8_string;
130−static Client *clients;
131−static Client *current;
132−static unsigned long col_active, col_inactive;
133−static unsigned long col_red;
128+static Atom net_wm_type, net_wm_type_dock, utf8_string;
129+static Client *clients, *current;
130+static unsigned long col_active, col_inactive, col_red;
134131 static volatile sig_atomic_t running = 1;
135−static Window swout[4];
136−static Window wmcheck;
137−static time_t sweep_pending;
138−static int sweep_x, sweep_y;
132+static Window swout[4], wmcheck, barwin, last_click_win;
133+static time_t sweep_pending, bar_deadline;
134+static int sweep_x, sweep_y, curdesk, bar_batt = -1, bar_onac;
139135 static unsigned int sweep_dx, sweep_dy;
140136 static Time last_click_time;
141−static Window last_click_win;
142−static int curdesk;
143137 static Client *deskfocus[NDESKS];
144−static Window barwin;
145138 static Pixmap barpix;
146139 static GC bargc;
147140 static XftDraw *bardraw;
148141 static XftColor bar_fg, bar_bg, bar_sel, bar_self, bar_tab;
149142 static XftColor bar_run, bar_exit, bar_desk[DESK_COLORS];
150−static unsigned long col_bar_bd;
151−static unsigned int barw, barh;
152−static int bar_batt = -1;
153−static int bar_onac;
154−static time_t bar_deadline;
155143
156144 static Client *bar_tabs[MAXCLIENTS];
157−static int bar_tab_x[MAXCLIENTS];
158−static int bar_tab_w[MAXCLIENTS];
159−static int bar_ntabs;
160−
161−static int bar_run_x, bar_run_w;
162−static int bar_desk_x[NDESKS], bar_desk_w;
163−static int bar_status_x;
164−static int bar_exit_x, bar_exit_w;
165−static int launch_visible;
145+static int bar_tab_x[MAXCLIENTS], bar_tab_w[MAXCLIENTS], bar_ntabs;
146+static int bar_run_x, bar_run_w, bar_desk_w, bar_status_x, bar_exit_x, bar_exit_w;
147+static int bar_desk_x[NDESKS];
148+static int launch_visible, launch_ncmds, launch_sel = -1, launch_scroll;
149+static int launch_filterlen, launch_nfiltered, launch_nitems;
166150 static char *launch_cmds[MAXCMDS];
167−static int launch_ncmds;
168−static int launch_sel = -1;
169−static int launch_scroll;
170151 static char launch_filter[256];
171−static int launch_filterlen;
172−static int launch_filtered[MAXCMDS];
173−static int launch_nfiltered;
174−static int launch_item_x[MAXCMDS];
175−static int launch_item_w[MAXCMDS];
152+static int launch_filtered[MAXCMDS], launch_item_x[MAXCMDS], launch_item_w[MAXCMDS];
176153 static int launch_nitems;
177154 static void bar_redraw(void);
178155
@@ -186,29 +163,16 @@ raisebar(void) · 7 unmodified lines
186163 static unsigned long
187164 getcolor(unsigned long rgb)
188165 {
189− XColor c;
190−
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;
166+ XColor c = {0, RGB16(rgb >> 16), RGB16(rgb >> 8), RGB16(rgb), DoRed | DoGreen | DoBlue, 0};
167+ return XAllocColor(dpy, DefaultColormap(dpy, screen), &c) ? c.pixel : WhitePixel(dpy, screen);
198168 }
199169
200170 static XftColor
201171 getxftcolor(unsigned long rgb)
202172 {
203− XRenderColor rc;
173+ XRenderColor rc = {RGB16(rgb >> 16), RGB16(rgb >> 8), RGB16(rgb), 0xFFFF};
204174 XftColor c = {0};
205−
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))
175+ if(!XftColorAllocValue(dpy, DefaultVisual(dpy, screen), DefaultColormap(dpy, screen), &rc, &c))
212176 c.pixel = WhitePixel(dpy, screen);
213177 return c;
214178 }
@@ -216,20 +180,12 @@ getxftcolor(unsigned long rgb) · 1 unmodified line
216180 static Cursor
217181 makecursor(Cursordata *d)
218182 {
219− Pixmap f, m;
220− Cursor cur;
221183 XColor bl, wh, dummy;
222−
223− XAllocNamedColor(dpy, DefaultColormap(dpy, screen),
224− "black", &bl, &dummy);
225− XAllocNamedColor(dpy, DefaultColormap(dpy, screen),
226− "white", &wh, &dummy);
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]);
184+ XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &bl, &dummy);
185+ XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "white", &wh, &dummy);
186+ Pixmap f = XCreatePixmapFromBitmapData(dpy, root, (char *)d->fore, d->width, d->width, 1, 0, 1);
187+ Pixmap m = XCreatePixmapFromBitmapData(dpy, root, (char *)d->mask, d->width, d->width, 1, 0, 1);
188+ Cursor cur = XCreatePixmapCursor(dpy, f, m, &bl, &wh, d->hot[0], d->hot[1]);
233189 XFreePixmap(dpy, f);
234190 XFreePixmap(dpy, m);
235191 return cur;
@@ -239,41 +195,19 @@ static int · 3 unmodified lines
239195 xft_textwidth(const char *s, int len)
240196 {
241197 XGlyphInfo ext;
242−
243198 XftTextExtentsUtf8(dpy, xftfont, (const FcChar8 *)s, len, &ext);
244199 return ext.xOff;
245200 }
246201
247−static int
248−handler(Display *d, XErrorEvent *e)
249−{
250− USED(d); USED(e);
251− return 0;
252−}
253−
254−static void
255−sigchld(int sig)
256−{
257− USED(sig);
258− while(waitpid(-1, NULL, WNOHANG) > 0)
259− ;
260−}
261−
262−static void
263−sigterm(int sig)
264−{
265− USED(sig);
266− running = 0;
267−}
202+static int handler(Display *d, XErrorEvent *e) { USED(d); USED(e); return 0; }
203+static void sigchld(int sig) { USED(sig); while(waitpid(-1, NULL, WNOHANG) > 0); }
204+static void sigterm(int sig) { USED(sig); running = 0; }
268205
269206 static void
270207 spawn(const char *cmd)
271208 {
272− pid_t p;
273−
274− p = fork();
275− if(p < 0)
276− return;
209+ pid_t p = fork();
210+ if(p < 0) return;
277211 if(p == 0){
278212 if(fork() == 0){
279213 setsid();
@@ -435,8 +369,6 @@ bar_drawbtn(int x, int w, const char *s, int len, int sel, XftColor *bg) · 155 unmodified lines
435369 if(w <= 0)
436370 return;
437371 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);
440372 XftDrawStringUtf8(bardraw, sel ? &bar_self : &bar_fg, xftfont,
441373 x + BAR_BTN_PAD, ty, (const FcChar8 *)s, len);
442374 }
@@ -455,8 +387,6 @@ launcher_draw(void) · 12 unmodified lines
455387 x = BAR_GAP;
456388
457389 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);
460390 XftDrawStringUtf8(bardraw, &bar_fg, xftfont,
461391 x + BAR_BTN_PAD, ty, (const FcChar8 *)launch_filter, launch_filterlen);
462392 XftTextExtentsUtf8(dpy, xftfont, (const FcChar8 *)launch_filter, launch_filterlen, &ext);
@@ -483,8 +413,6 @@ launcher_draw(void) · 20 unmodified lines
483413 XftDrawRect(bardraw, sel ? &bar_sel : &bar_tab, x, 0, (unsigned int)tw, barh);
484414 XftDrawStringUtf8(bardraw, sel ? &bar_self : &bar_fg, xftfont,
485415 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);
488416 x += tw + BAR_GAP;
489417 }
490418
@@ -680,9 +608,6 @@ bar_drawtabs(int x, int tabarea, int rightw) · 189 unmodified lines
680608 tabx, 0, (unsigned int)tw, barh);
681609 XftDrawStringUtf8(bardraw, sel ? &bar_self : &bar_fg, xftfont,
682610 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);
686611 tabx += tw + BAR_GAP;
687612 }
688613 bar_ntabs = drawn;
@@ -1007,6 +932,16 @@ applylayout(Client *c) · 318 unmodified lines
1007932 sendconfig(c);
1008933 }
1009934
935+static Client *
936+topclient(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+
1010945 static void
1011946 switch_to(int n)
1012947 {
@@ -1025,19 +960,13 @@ switch_to(int n) · 12 unmodified lines
1025960 static void
1026961 sendtodesktop(Client *c, int n)
1027962 {
1028− Client *next;
1029−
1030963 if(!c || n < 0 || n >= NDESKS || n == curdesk)
1031964 return;
1032965 c->virt = n;
1033966 ewmh_set(c->win, net_wm_desk, XA_CARDINAL, 32, &(long){n}, 1);
1034967 XUnmapWindow(dpy, c->frame);
1035− if(current == c){
1036− for(next = clients; next; next = next->next)
1037− if(next->virt == curdesk)
1038− break;
1039− focus(next);
1040− }
968+ if(current == c)
969+ focus(topclient());
1041970 deskfocus[n] = c;
1042971 switch_to(n);
1043972 }
@@ -1190,10 +1119,7 @@ unmanage(Client *c) · 146 unmodified lines
11901119 ewmh_updateclients();
11911120 if(current == c){
11921121 current = NULL;
1193− for(c = clients; c; c = c->next)
1194− if(c->virt == curdesk)
1195− break;
1196− focus(c);
1122+ focus(topclient());
11971123 } else
11981124 bar_redraw();
11991125 free(old->label);
@@ -1604,10 +1530,7 @@ buttonpress(XButtonEvent *e) · 404 unmodified lines
16041530 XUnmapWindow(dpy, current->frame);
16051531 deskfocus[i] = current;
16061532 ewmh_updateclients();
1607− for(c = clients; c; c = c->next)
1608− if(c->virt == curdesk)
1609− break;
1610− focus(c);
1533+ focus(topclient());
16111534 } else if(btn == Button3)
16121535 sendtodesktop(current, i);
16131536 return;
@@ -1787,7 +1710,6 @@ static void · 173 unmodified lines
17871710 clientmessage(XClientMessageEvent *e)
17881711 {
17891712 Client *c;
1790− int fs;
17911713
17921714 if(e->message_type == net_cur_desk){
17931715 if(e->data.l[0] >= 0 && e->data.l[0] < NDESKS)
@@ -1802,6 +1724,7 @@ clientmessage(XClientMessageEvent *e) · 8 unmodified lines
18021724 switch_to(c->virt);
18031725 focus(c);
18041726 } else if(e->message_type == net_wm_state){
1727+ int fs;
18051728 if((Atom)e->data.l[1] != net_wm_state_fs && (Atom)e->data.l[2] != net_wm_state_fs)
18061729 return;
18071730 fs = e->data.l[0] == 1 || (e->data.l[0] == 2 && !c->fullscreen);
@@ -1809,8 +1732,15 @@ clientmessage(XClientMessageEvent *e) · 1 unmodified line
18091732 return;
18101733 if(fs) savegeom(c);
18111734 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+ }
18121742 applylayout(c);
1813− fs ? XRaiseWindow(dpy, c->frame) : raisebar();
1743+ focus(c);
18141744 }
18151745 }
18161746
@@ -1846,7 +1776,6 @@ setup_bar(void) · 29 unmodified lines
18461776 bar_desk[1] = getxftcolor(COL_BAR_DESK1);
18471777 bar_desk[2] = getxftcolor(COL_BAR_DESK2);
18481778 bar_desk[3] = getxftcolor(COL_BAR_DESK3);
1849− col_bar_bd = getcolor(COL_BAR_BD);
18501779
18511780 barw = sw;
18521781 barh = (unsigned int)(xftfont->ascent + xftfont->descent) + BAR_PAD * 2;
config.h+7−8
@@ -1,16 +1,15 @@
11 /* Colors - Plan 9 palette */
2−#define COL_ACTIVE 0x55AAAA /* active border - dark cyan */
2+#define COL_ACTIVE 0x55AAAA /* active border - teal */
33 #define COL_INACTIVE 0x9EEEEE /* inactive border - pale cyan */
4−#define COL_SWEEP_BD 0xDD0000 /* sweep outline - red */
5−#define COL_ROOT_BG 0x777777 /* root background - grey */
4+#define COL_SWEEP_BD 0xAA0000 /* sweep outline - red */
5+#define COL_ROOT_BG 0x999999 /* root background - grey */
66
77 /* Bar colors */
88 #define COL_BAR_BG 0xEAFFFF /* background - pale cyan */
99 #define COL_BAR_FG 0x000000 /* text - black */
10−#define COL_BAR_SEL 0x9EEEEE /* selection - pale blue */
11−#define COL_BAR_SELF 0x005555 /* selection text - dark teal */
10+#define COL_BAR_SEL 0x55AAAA /* selection - teal */
11+#define COL_BAR_SELF 0xFFFFFF /* selection text - white */
1212 #define COL_BAR_TAB 0xEEFFEE /* tab - pale green */
13−#define COL_BAR_BD 0x88AAAA /* border - muted cyan */
1413 #define COL_BAR_RUN 0x99EE99 /* run button - green */
1514 #define COL_BAR_EXIT 0xEE9999 /* exit button - red */
1615 #define COL_BAR_DESK0 0xEAFFEA /* desk empty */
@@ -20,11 +19,11 @@ · 3 unmodified lines
2019
2120 /* Geometry */
2221 #define BORDER 4
23−#define CORNER 25
22+#define CORNER 32
2423
2524 /* Bar */
2625 #define BAR_PAD 2
27−#define BAR_BTN_PAD 4
26+#define BAR_BTN_PAD 2
2827 #define BAR_GAP 2
2928 #define BAR_REFRESH 60
3029 #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