diff --git a/Makefile b/Makefile index 34d8b80..b176c9d 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ debug: $(CC) -o goomwwm-debug goomwwm.c $(CFLAGS) -g -DDEBUG $(LDADD) proto: - cat *.c | egrep '^(void|int|char|unsigned|client|Window|winlist|textbox|XWindow)' | sed -r 's/\)/);/' > proto.h + cat *.c | egrep '^(void|int|char|unsigned|client|Window|winlist|box|textbox|XWindow)' | sed -r 's/\)/);/' > proto.h docs: pandoc -s -w man goomwwm.md -o goomwwm.1 diff --git a/box.c b/box.c index 03c0deb..12793ac 100644 --- a/box.c +++ b/box.c @@ -31,11 +31,17 @@ box* box_create(Window parent, bitmap flags, short x, short y, short w, short h, b->flags = flags; b->parent = parent; + box_color(b, color); + + b->window = XCreateSimpleWindow(display, b->parent, 0, 0, 1, 1, 0, None, b->color); - b->window = XCreateSimpleWindow(display, b->parent, 0, 0, 1, 1, 0, None, None); + if (b->flags & BOX_OVERRIDE) + { + XSetWindowAttributes attr; attr.override_redirect = True; + XChangeWindowAttributes(display, b->window, CWOverrideRedirect, &attr); + } box_moveresize(b, x, y, w, h); - box_color(b, color); return b; } diff --git a/client.c b/client.c index 4153fde..1461235 100644 --- a/client.c +++ b/client.c @@ -1046,19 +1046,17 @@ void client_flash(client *c, char *color, int delay, int title) message_box(delay, c->x+c->w/2, c->y+c->h/2, config_title_fg, config_title_bg, config_title_bc, c->title); // four coloured squares in the window's corners - unsigned int bg = color_get(color); - Window tl = window_create_override(x1, y1, config_flash_width, config_flash_width, bg); - Window tr = window_create_override(x2, y1, config_flash_width, config_flash_width, bg); - Window bl = window_create_override(x1, y2, config_flash_width, config_flash_width, bg); - Window br = window_create_override(x2, y2, config_flash_width, config_flash_width, bg); + box *tl = box_create(root, BOX_OVERRIDE, x1, y1, config_flash_width, config_flash_width, color); + box *tr = box_create(root, BOX_OVERRIDE, x2, y1, config_flash_width, config_flash_width, color); + box *bl = box_create(root, BOX_OVERRIDE, x1, y2, config_flash_width, config_flash_width, color); + box *br = box_create(root, BOX_OVERRIDE, x2, y2, config_flash_width, config_flash_width, color); - XMapRaised(display, tl); XMapRaised(display, tr); - XMapRaised(display, bl); XMapRaised(display, br); + box_show(tl); box_show(tr); box_show(bl); box_show(br); - XSync(display, False); usleep(delay*1000); + XSync(display, False); + usleep(delay*1000); - XDestroyWindow(display, tl); XDestroyWindow(display, tr); - XDestroyWindow(display, bl); XDestroyWindow(display, br); + box_free(tl); box_free(tr); box_free(bl); box_free(br); exit(EXIT_SUCCESS); } diff --git a/goomwwm.h b/goomwwm.h index e0b495e..6dff75e 100644 --- a/goomwwm.h +++ b/goomwwm.h @@ -51,6 +51,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. typedef unsigned char bool; typedef unsigned long long bitmap; +#define BOX_OVERRIDE 1<<0 + typedef struct { bitmap flags; Window window, parent; @@ -533,7 +535,7 @@ Time latest = CurrentTime; struct mouse_drag { XButtonEvent button; XWindowAttributes attr; - Window overlay; + box *overlay; short x, y, w, h; unsigned int flags; }; diff --git a/handle.c b/handle.c index 1af5715..e7c01fe 100644 --- a/handle.c +++ b/handle.c @@ -370,11 +370,11 @@ void handle_buttonpress(XEvent *ev) take_pointer(c->window, PointerMotionMask|ButtonReleaseMask, None); mouse_dragger = allocate_clear(sizeof(struct mouse_drag)); - mouse_dragger->overlay = window_create(c->x, c->y, c->w, c->h, color_get(config_border_blur)); + mouse_dragger->overlay = box_create(root, BOX_OVERRIDE, c->x, c->y, c->w, c->h, config_border_blur); unsigned long opacity = 0xffffffff / 2; // no map yet, see motionnotify - window_set_cardinal_prop(mouse_dragger->overlay, netatoms[_NET_WM_WINDOW_OPACITY], &opacity, 1); + window_set_cardinal_prop(mouse_dragger->overlay->window, netatoms[_NET_WM_WINDOW_OPACITY], &opacity, 1); memcpy(&mouse_dragger->attr, &c->xattr, sizeof(c->xattr)); memcpy(&mouse_dragger->button, &ev->xbutton, sizeof(ev->xbutton)); @@ -430,7 +430,7 @@ void handle_buttonrelease(XEvent *ev) } release_pointer(); - XDestroyWindow(display, mouse_dragger->overlay); + box_free(mouse_dragger->overlay); free(mouse_dragger); mouse_dragger = NULL; @@ -452,7 +452,8 @@ void handle_motionnotify(XEvent *ev) client *c = client_create(ev->xmotion.window); if (c && c->manage && mouse_dragger) { - XMapRaised(display, mouse_dragger->overlay); + box_show(mouse_dragger->overlay); + client_extended_data(c); int xd = ev->xbutton.x_root - mouse_dragger->button.x_root; int yd = ev->xbutton.y_root - mouse_dragger->button.y_root; @@ -477,7 +478,7 @@ void handle_motionnotify(XEvent *ev) mouse_dragger->h = h; //XMoveResizeWindow(display, mouse_dragger->overlay, x, y, w, h); - client_moveresize(client_create(mouse_dragger->overlay), mouse_dragger->flags, x, y, w, h); + client_moveresize(client_create(mouse_dragger->overlay->window), mouse_dragger->flags, x, y, w, h); } } diff --git a/proto.h b/proto.h index e38d3ff..938a333 100644 --- a/proto.h +++ b/proto.h @@ -1,3 +1,4 @@ +box* box_create(Window parent, bitmap flags, short x, short y, short w, short h, char *color); void box_color(box *b, char *color); void box_moveresize(box *b, short x, short y, short w, short h); void box_show(box *b); @@ -178,8 +179,6 @@ int take_pointer(Window w, unsigned long mask, Cursor cur); void release_keyboard(); void release_pointer(); void message_box(int delay, int x, int y, char *fgc, char *bgc, char *bc, char *txt); -Window window_create_override(int x, int y, int w, int h, unsigned int color); -Window window_create(int x, int y, int w, int h, unsigned int color); void notice(const char *fmt, ...); void notification(int delay, const char *fmt, ...); void event_log(const char *e, Window w); diff --git a/util.c b/util.c index 739d2e6..57f9d83 100644 --- a/util.c +++ b/util.c @@ -222,20 +222,20 @@ void message_box(int delay, int x, int y, char *fgc, char *bgc, char *bc, char * display = XOpenDisplay(0x0); - Window box = window_create_override(0, 0, 1, 1, color_get(config_title_bg)); + box *b = box_create(root, BOX_OVERRIDE, 0, 0, 1, 1, config_title_bg); - textbox *text = textbox_create(box, TB_CENTER|TB_AUTOHEIGHT|TB_AUTOWIDTH, + textbox *text = textbox_create(b->window, TB_CENTER|TB_AUTOHEIGHT|TB_AUTOWIDTH, 8, 5, 1, 1, config_title_font, config_title_fg, config_title_bg, txt, NULL); - XMoveResizeWindow(display, box, + box_moveresize(b, MIN(mon.x+mon.w-text->w-26, MAX(mon.x+26, x - text->w/2)), MIN(mon.y+mon.h-text->h-20, MAX(mon.y+20, y - text->h/2)), text->w + 16, text->h + 10); - XSelectInput(display, box, ExposureMask); + XSelectInput(display, b->window, ExposureMask); textbox_show(text); - XMapRaised(display, box); + box_show(b); double stamp = timestamp(); while ((timestamp()-stamp) < (double)delay/1000) @@ -252,31 +252,9 @@ void message_box(int delay, int x, int y, char *fgc, char *bgc, char *bc, char * } textbox_free(text); - exit(EXIT_SUCCESS); -} + box_free(b); -// wrapper for XCreateSimpleWindow so we can track our own windows -Window window_create_override(int x, int y, int w, int h, unsigned int color) -{ - Window win = XCreateSimpleWindow(display, root, x, y, w, h, 0, None, color); - XSetWindowAttributes attr; attr.override_redirect = True; - XChangeWindowAttributes(display, win, CWOverrideRedirect, &attr); - // pre-create window's cache, so we know it's ours later - wincache *cache = allocate_clear(sizeof(wincache)); - winlist_append(windows, win, cache); - cache->is_ours = 1; - return win; -} - -// wrapper for XCreateSimpleWindow so we can track our own windows -Window window_create(int x, int y, int w, int h, unsigned int color) -{ - Window win = XCreateSimpleWindow(display, root, x, y, w, h, 0, None, color); - // pre-create window's cache, so we know it's ours later - wincache *cache = allocate_clear(sizeof(wincache)); - winlist_append(windows, win, cache); - cache->is_ours = 1; - return win; + exit(EXIT_SUCCESS); } // bottom right of screen