From 0bb4b5ca862692fa875624a0f6502b875b065235 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 22 May 2019 21:23:08 -0400 Subject: [PATCH] always use xft --- .gitignore | 2 + Makefile | 21 +- client.c | 503 +++++++++++-------------- events.c | 27 -- main.c | 336 ++++++++--------- manage.c | 1020 +++++++++++++++++++++++++-------------------------- menufile.c | 294 ++++++++------- misc.c | 572 ++++++++++++++--------------- new.c | 307 ++++++++-------- taskbar.c | 692 +++++++++++++++++----------------- windowlab.h | 96 ++--- 11 files changed, 1838 insertions(+), 2032 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3ff85b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +tags diff --git a/Makefile b/Makefile index 3c6d765..018424c 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,9 @@ # Makefile for WindowLab -# Comment out to remove shape support (for X11R5 or just a tiny bin) -DEFINES += -DSHAPE -EXTRA_LIBS += -lXext - # Set this to the hardcoded location of all files if it's not / PREFIX = /usr/local -# Set this to the directory, below PREFIX, where man pages +# Set this to the directory, below PREFIX, where man pages # are expected. Below this directory, the target "install" # will put "windowlab.1x" in section "man1". MANBASE = /man @@ -34,26 +30,27 @@ DEFINES += -DDEF_MENURC="\"$(MENURC)\"" # Uncomment to add freetype support (requires XFree86 4.0.2 or later) # This needs -lXext above, even if you have disabled shape support -#DEFINES += -DXFT -#EXTRA_INC += `pkg-config --cflags xft` -#EXTRA_LIBS += `pkg-config --libs xft` +DEFINES += -DXFT # Uncomment for debugging info (abandon all hope, ye who enter here) #DEFINES += -DDEBUG # -------------------------------------------------------------------- -CC = gcc +CC = cc ifndef CFLAGS -CFLAGS = -g -O2 -Wall -W +CFLAGS = -g -O2 -std=c99 -pedantic -Wall -Wextra -W endif BINDIR = $(DESTDIR)$(PREFIX)/bin MANDIR = $(DESTDIR)$(PREFIX)$(MANBASE)/man1 CFGDIR = $(DESTDIR)$(SYSCONFDIR) -INCLUDES = -I$(XROOT)/include $(EXTRA_INC) + +INCLUDES = -I$(XROOT)/include \ + -I$(XROOT)/include/freetype2 + LDPATH = -L$(XROOT)/lib -LIBS = -lX11 $(EXTRA_LIBS) +LIBS = -lX11 -lXft PROG = windowlab MANPAGE = windowlab.1x diff --git a/client.c b/client.c index f7774ab..3ef5cc6 100644 --- a/client.c +++ b/client.c @@ -22,30 +22,30 @@ Client *find_client(Window w, int mode) { - Client *c = head_client; - if (mode == FRAME) - { - while (c != NULL) - { - if (c->frame == w) - { - return c; - } - c = c->next; - } - } - else // WINDOW - { - while (c != NULL) - { - if (c->window == w) - { - return c; - } - c = c->next; - } - } - return NULL; + Client *c = head_client; + if (mode == FRAME) + { + while (c != NULL) + { + if (c->frame == w) + { + return c; + } + c = c->next; + } + } + else // WINDOW + { + while (c != NULL) + { + if (c->window == w) + { + return c; + } + c = c->next; + } + } + return NULL; } /* Attempt to follow the ICCCM by explicitly specifying 32 bits for @@ -53,12 +53,12 @@ Client *find_client(Window w, int mode) void set_wm_state(Client *c, int state) { - CARD32 data[2]; + CARD32 data[2]; - data[0] = state; - data[1] = None; //Icon? We don't need no steenking icon. + data[0] = state; + data[1] = None; //Icon? We don't need no steenking icon. - XChangeProperty(dsply, c->window, wm_state, wm_state, 32, PropModeReplace, (unsigned char *)data, 2); + XChangeProperty(dsply, c->window, wm_state, wm_state, 32, PropModeReplace, (unsigned char *)data, 2); } /* If we can't find a WM_STATE we're going to have to assume @@ -69,18 +69,18 @@ void set_wm_state(Client *c, int state) long get_wm_state(Client *c) { - Atom real_type; - int real_format; - long state = WithdrawnState; - unsigned long items_read, items_left; - unsigned char *data; - - if (XGetWindowProperty(dsply, c->window, wm_state, 0L, 2L, False, wm_state, &real_type, &real_format, &items_read, &items_left, &data) == Success && items_read) - { - state = *(long *)data; - XFree(data); - } - return state; + Atom real_type; + int real_format; + long state = WithdrawnState; + unsigned long items_read, items_left; + unsigned char *data; + + if (XGetWindowProperty(dsply, c->window, wm_state, 0L, 2L, False, wm_state, &real_type, &real_format, &items_read, &items_left, &data) == Success && items_read) + { + state = *(long *)data; + XFree(data); + } + return state; } /* This will need to be called whenever we update our Client stuff. @@ -88,20 +88,20 @@ long get_wm_state(Client *c) void send_config(Client *c) { - XConfigureEvent ce; - - ce.type = ConfigureNotify; - ce.event = c->window; - ce.window = c->window; - ce.x = c->x; - ce.y = c->y; - ce.width = c->width; - ce.height = c->height; - ce.border_width = 0; - ce.above = None; - ce.override_redirect = 0; - - XSendEvent(dsply, c->window, False, StructureNotifyMask, (XEvent *)&ce); + XConfigureEvent ce; + + ce.type = ConfigureNotify; + ce.event = c->window; + ce.window = c->window; + ce.x = c->x; + ce.y = c->y; + ce.width = c->width; + ce.height = c->height; + ce.border_width = 0; + ce.above = None; + ce.override_redirect = 0; + + XSendEvent(dsply, c->window, False, StructureNotifyMask, (XEvent *)&ce); } /* After pulling my hair out trying to find some way to tell if a @@ -117,121 +117,102 @@ void send_config(Client *c) void remove_client(Client *c, int mode) { - Client *p; + Client *p; - XGrabServer(dsply); - XSetErrorHandler(ignore_xerror); + XGrabServer(dsply); + XSetErrorHandler(ignore_xerror); #ifdef DEBUG - err("removing %s, %d: %d left", c->name, mode, XPending(dsply)); + err("removing %s, %d: %d left", c->name, mode, XPending(dsply)); #endif - if (mode == WITHDRAW) - { - set_wm_state(c, WithdrawnState); - } - else //REMAP - { - XMapWindow(dsply, c->window); - } - gravitate(c, REMOVE_GRAVITY); - XReparentWindow(dsply, c->window, root, c->x, c->y); -#ifdef MWM_HINTS - if (c->has_border) - { - XSetWindowBorderWidth(dsply, c->window, 1); - } -#else - XSetWindowBorderWidth(dsply, c->window, 1); -#endif -#ifdef XFT - XftDrawDestroy(c->xftdraw); -#endif - XRemoveFromSaveSet(dsply, c->window); - XDestroyWindow(dsply, c->frame); - - if (head_client == c) - { - head_client = c->next; - } - else - { - for (p = head_client; p && p->next; p = p->next) - { - if (p->next == c) - { - p->next = c->next; - } - } - } - if (c->name != NULL) - { - XFree(c->name); - } - if (c->size) - { - XFree(c->size); - } - if (c == fullscreen_client) - { - fullscreen_client = NULL; - } - if (c == focused_client) - { - focused_client = NULL; - check_focus(get_prev_focused()); - } - free(c); - - XSync(dsply, False); - XSetErrorHandler(handle_xerror); - XUngrabServer(dsply); - - redraw_taskbar(); + if (mode == WITHDRAW) + { + set_wm_state(c, WithdrawnState); + } + else //REMAP + { + XMapWindow(dsply, c->window); + } + gravitate(c, REMOVE_GRAVITY); + XReparentWindow(dsply, c->window, root, c->x, c->y); + XSetWindowBorderWidth(dsply, c->window, 1); + XftDrawDestroy(c->xftdraw); + XRemoveFromSaveSet(dsply, c->window); + XDestroyWindow(dsply, c->frame); + + if (head_client == c) + { + head_client = c->next; + } + else + { + for (p = head_client; p && p->next; p = p->next) + { + if (p->next == c) + { + p->next = c->next; + } + } + } + if (c->name != NULL) + { + XFree(c->name); + } + if (c->size) + { + XFree(c->size); + } + if (c == fullscreen_client) + { + fullscreen_client = NULL; + } + if (c == focused_client) + { + focused_client = NULL; + check_focus(get_prev_focused()); + } + free(c); + + XSync(dsply, False); + XSetErrorHandler(handle_xerror); + XUngrabServer(dsply); + + redraw_taskbar(); } void redraw(Client *c) { - if (c == fullscreen_client) - { - return; - } -#ifdef MWM_HINTS - if (!c->has_title) - { - return; - } -#endif - XDrawLine(dsply, c->frame, border_gc, 0, BARHEIGHT() - DEF_BORDERWIDTH + DEF_BORDERWIDTH / 2, c->width, BARHEIGHT() - DEF_BORDERWIDTH + DEF_BORDERWIDTH / 2); - // clear text part of bar - if (c == focused_client) - { - XFillRectangle(dsply, c->frame, active_gc, 0, 0, c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 3), BARHEIGHT() - DEF_BORDERWIDTH); - } - else - { - XFillRectangle(dsply, c->frame, inactive_gc, 0, 0, c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 3), BARHEIGHT() - DEF_BORDERWIDTH); - } - if (!c->trans && c->name != NULL) - { -#ifdef XFT - XftDrawString8(c->xftdraw, &xft_detail, xftfont, SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name)); -#else - XDrawString(dsply, c->frame, text_gc, SPACE, SPACE + font->ascent, c->name, strlen(c->name)); -#endif - } - if (c == focused_client) - { - draw_hide_button(c, &text_gc, &active_gc); - draw_toggledepth_button(c, &text_gc, &active_gc); - draw_close_button(c, &text_gc, &active_gc); - } - else - { - draw_hide_button(c, &text_gc, &inactive_gc); - draw_toggledepth_button(c, &text_gc, &inactive_gc); - draw_close_button(c, &text_gc, &inactive_gc); - } + if (c == fullscreen_client) + { + return; + } + XDrawLine(dsply, c->frame, border_gc, 0, BARHEIGHT() - DEF_BORDERWIDTH + DEF_BORDERWIDTH / 2, c->width, BARHEIGHT() - DEF_BORDERWIDTH + DEF_BORDERWIDTH / 2); + // clear text part of bar + if (c == focused_client) + { + XFillRectangle(dsply, c->frame, active_gc, 0, 0, c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 3), BARHEIGHT() - DEF_BORDERWIDTH); + } + else + { + XFillRectangle(dsply, c->frame, inactive_gc, 0, 0, c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 3), BARHEIGHT() - DEF_BORDERWIDTH); + } + if (!c->trans && c->name != NULL) + { + XftDrawString8(c->xftdraw, &xft_detail, xftfont, SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name)); + } + if (c == focused_client) + { + draw_hide_button(c, &text_gc, &active_gc); + draw_toggledepth_button(c, &text_gc, &active_gc); + draw_close_button(c, &text_gc, &active_gc); + } + else + { + draw_hide_button(c, &text_gc, &inactive_gc); + draw_toggledepth_button(c, &text_gc, &inactive_gc); + draw_close_button(c, &text_gc, &inactive_gc); + } } /* Window gravity is a mess to explain, but we don't need to do much @@ -244,22 +225,22 @@ void redraw(Client *c) void gravitate(Client *c, int multiplier) { - int dy = 0; - int gravity = (c->size->flags & PWinGravity) ? c->size->win_gravity : NorthWestGravity; - - switch (gravity) - { - case NorthWestGravity: - case NorthEastGravity: - case NorthGravity: - dy = BARHEIGHT(); - break; - case CenterGravity: - dy = BARHEIGHT()/2; - break; - } - - c->y += multiplier * dy; + int dy = 0; + int gravity = (c->size->flags & PWinGravity) ? c->size->win_gravity : NorthWestGravity; + + switch (gravity) + { + case NorthWestGravity: + case NorthEastGravity: + case NorthGravity: + dy = BARHEIGHT(); + break; + case CenterGravity: + dy = BARHEIGHT()/2; + break; + } + + c->y += multiplier * dy; } /* Well, the man pages for the shape extension say nothing, but I was @@ -270,127 +251,89 @@ void gravitate(Client *c, int multiplier) * server will paint the border in the region between the two. (I knew * that using X borders would get me eventually... ;-)) */ -#ifdef SHAPE -void set_shape(Client *c) -{ - int n, order; - XRectangle temp, *dummy; - - dummy = XShapeGetRectangles(dsply, c->window, ShapeBounding, &n, &order); - if (n > 1) - { - XShapeCombineShape(dsply, c->frame, ShapeBounding, 0, BARHEIGHT(), c->window, ShapeBounding, ShapeSet); - temp.x = -BORDERWIDTH(c); - temp.y = -BORDERWIDTH(c); - temp.width = c->width + (2 * BORDERWIDTH(c)); - temp.height = BARHEIGHT() + BORDERWIDTH(c); - XShapeCombineRectangles(dsply, c->frame, ShapeBounding, 0, 0, &temp, 1, ShapeUnion, YXBanded); - temp.x = 0; - temp.y = 0; - temp.width = c->width; - temp.height = BARHEIGHT() - BORDERWIDTH(c); - XShapeCombineRectangles(dsply, c->frame, ShapeClip, 0, BARHEIGHT(), &temp, 1, ShapeUnion, YXBanded); - c->has_been_shaped = 1; - } - else - { - if (c->has_been_shaped) - { - // I can't find a 'remove all shaping' function... - temp.x = -BORDERWIDTH(c); - temp.y = -BORDERWIDTH(c); - temp.width = c->width + (2 * BORDERWIDTH(c)); - temp.height = c->height + BARHEIGHT() + (2 * BORDERWIDTH(c)); - XShapeCombineRectangles(dsply, c->frame, ShapeBounding, 0, 0, &temp, 1, ShapeSet, YXBanded); - } - } - XFree(dummy); -} -#endif - void check_focus(Client *c) { - if (c != NULL) - { - XSetInputFocus(dsply, c->window, RevertToNone, CurrentTime); - XInstallColormap(dsply, c->cmap); - } - if (c != focused_client) - { - Client *old_focused = focused_client; - focused_client = c; - focus_count++; - if (c != NULL) - { - c->focus_order = focus_count; - redraw(c); - } - if (old_focused != NULL) - { - redraw(old_focused); - } - redraw_taskbar(); - } + if (c != NULL) + { + XSetInputFocus(dsply, c->window, RevertToNone, CurrentTime); + XInstallColormap(dsply, c->cmap); + } + if (c != focused_client) + { + Client *old_focused = focused_client; + focused_client = c; + focus_count++; + if (c != NULL) + { + c->focus_order = focus_count; + redraw(c); + } + if (old_focused != NULL) + { + redraw(old_focused); + } + redraw_taskbar(); + } } Client *get_prev_focused(void) { - Client *c = head_client; - Client *prev_focused = NULL; - unsigned int highest = 0; - - while (c != NULL) - { - if (!c->hidden && c->focus_order > highest) - { - highest = c->focus_order; - prev_focused = c; - } - c = c->next; - } - return prev_focused; + Client *c = head_client; + Client *prev_focused = NULL; + unsigned int highest = 0; + + while (c != NULL) + { + if (!c->hidden && c->focus_order > highest) + { + highest = c->focus_order; + prev_focused = c; + } + c = c->next; + } + return prev_focused; } void draw_hide_button(Client *c, GC *detail_gc, GC *background_gc) { - int x, topleft_offset; - x = c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 3); - topleft_offset = (BARHEIGHT() / 2) - 5; // 5 being ~half of 9 - XFillRectangle(dsply, c->frame, *background_gc, x, 0, BARHEIGHT() - DEF_BORDERWIDTH, BARHEIGHT() - DEF_BORDERWIDTH); - - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 4, topleft_offset + 2, x + topleft_offset + 4, topleft_offset + 0); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 6, topleft_offset + 2, x + topleft_offset + 7, topleft_offset + 1); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 6, topleft_offset + 4, x + topleft_offset + 8, topleft_offset + 4); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 6, topleft_offset + 6, x + topleft_offset + 7, topleft_offset + 7); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 4, topleft_offset + 6, x + topleft_offset + 4, topleft_offset + 8); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 2, topleft_offset + 6, x + topleft_offset + 1, topleft_offset + 7); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 2, topleft_offset + 4, x + topleft_offset + 0, topleft_offset + 4); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 2, topleft_offset + 2, x + topleft_offset + 1, topleft_offset + 1); + int x, topleft_offset; + x = c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 3); + topleft_offset = (BARHEIGHT() / 2) - 5; // 5 being ~half of 9 + XFillRectangle(dsply, c->frame, *background_gc, x, 0, BARHEIGHT() - DEF_BORDERWIDTH, BARHEIGHT() - DEF_BORDERWIDTH); + + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 4, topleft_offset + 2, x + topleft_offset + 4, topleft_offset + 0); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 6, topleft_offset + 2, x + topleft_offset + 7, topleft_offset + 1); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 6, topleft_offset + 4, x + topleft_offset + 8, topleft_offset + 4); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 6, topleft_offset + 6, x + topleft_offset + 7, topleft_offset + 7); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 4, topleft_offset + 6, x + topleft_offset + 4, topleft_offset + 8); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 2, topleft_offset + 6, x + topleft_offset + 1, topleft_offset + 7); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 2, topleft_offset + 4, x + topleft_offset + 0, topleft_offset + 4); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 2, topleft_offset + 2, x + topleft_offset + 1, topleft_offset + 1); } void draw_toggledepth_button(Client *c, GC *detail_gc, GC *background_gc) { - int x, topleft_offset; - x = c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 2); - topleft_offset = (BARHEIGHT() / 2) - 6; // 6 being ~half of 11 - XFillRectangle(dsply, c->frame, *background_gc, x, 0, BARHEIGHT() - DEF_BORDERWIDTH, BARHEIGHT() - DEF_BORDERWIDTH); + int x, topleft_offset; + x = c->width - ((BARHEIGHT() - DEF_BORDERWIDTH) * 2); + topleft_offset = (BARHEIGHT() / 2) - 6; // 6 being ~half of 11 + XFillRectangle(dsply, c->frame, *background_gc, x, 0, BARHEIGHT() - DEF_BORDERWIDTH, BARHEIGHT() - DEF_BORDERWIDTH); - XDrawRectangle(dsply, c->frame, *detail_gc, x + topleft_offset, topleft_offset, 7, 7); - XDrawRectangle(dsply, c->frame, *detail_gc, x + topleft_offset + 3, topleft_offset + 3, 7, 7); + XDrawRectangle(dsply, c->frame, *detail_gc, x + topleft_offset, topleft_offset, 7, 7); + XDrawRectangle(dsply, c->frame, *detail_gc, x + topleft_offset + 3, topleft_offset + 3, 7, 7); } void draw_close_button(Client *c, GC *detail_gc, GC *background_gc) { - int x, topleft_offset; - x = c->width - (BARHEIGHT() - DEF_BORDERWIDTH); - topleft_offset = (BARHEIGHT() / 2) - 5; // 5 being ~half of 9 - XFillRectangle(dsply, c->frame, *background_gc, x, 0, BARHEIGHT() - DEF_BORDERWIDTH, BARHEIGHT() - DEF_BORDERWIDTH); - - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset, x + topleft_offset + 8, topleft_offset + 7); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset + 1, x + topleft_offset + 7, topleft_offset + 7); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset, topleft_offset + 1, x + topleft_offset + 7, topleft_offset + 8); - - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset, topleft_offset + 7, x + topleft_offset + 7, topleft_offset); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset + 7, x + topleft_offset + 7, topleft_offset + 1); - XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset + 8, x + topleft_offset + 8, topleft_offset + 1); + int x, topleft_offset; + x = c->width - (BARHEIGHT() - DEF_BORDERWIDTH); + topleft_offset = (BARHEIGHT() / 2) - 5; // 5 being ~half of 9 + XFillRectangle(dsply, c->frame, *background_gc, x, 0, BARHEIGHT() - DEF_BORDERWIDTH, BARHEIGHT() - DEF_BORDERWIDTH); + + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset, x + topleft_offset + 8, topleft_offset + 7); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset + 1, x + topleft_offset + 7, topleft_offset + 7); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset, topleft_offset + 1, x + topleft_offset + 7, topleft_offset + 8); + + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset, topleft_offset + 7, x + topleft_offset + 7, topleft_offset); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset + 7, x + topleft_offset + 7, topleft_offset + 1); + XDrawLine(dsply, c->frame, *detail_gc, x + topleft_offset + 1, topleft_offset + 8, x + topleft_offset + 8, topleft_offset + 1); } diff --git a/events.c b/events.c index 52cc850..bb37743 100644 --- a/events.c +++ b/events.c @@ -35,9 +35,6 @@ static void handle_property_change(XPropertyEvent *); static void handle_enter_event(XCrossingEvent *); static void handle_colormap_change(XColormapEvent *); static void handle_expose_event(XExposeEvent *); -#ifdef SHAPE -static void handle_shape_change(XShapeEvent *); -#endif static int interruptible_XNextEvent(XEvent *event); @@ -96,13 +93,6 @@ void do_event_loop(void) case Expose: handle_expose_event(&ev.xexpose); break; -#ifdef SHAPE - default: - if (shape && ev.type == shape_event) - { - handle_shape_change((XShapeEvent *)&ev); - } -#endif } } } @@ -385,12 +375,6 @@ static void handle_configure_request(XConfigureRequestEvent *e) //wc.sibling = e->above; //wc.stack_mode = e->detail; XConfigureWindow(dsply, c->frame, e->value_mask, &wc); -#ifdef SHAPE - if (e->value_mask & (CWWidth|CWHeight)) - { - set_shape(c); - } -#endif send_config(c); // start setting up the next call wc.x = 0; @@ -608,17 +592,6 @@ static void handle_expose_event(XExposeEvent *e) } } -#ifdef SHAPE -static void handle_shape_change(XShapeEvent *e) -{ - Client *c = find_client(e->window, WINDOW); - if (c != NULL) - { - set_shape(c); - } -} -#endif - /* interruptibleXNextEvent() was originally taken from Blender's source code * and came with the following copyright notice: */ diff --git a/main.c b/main.c index ca18501..4a94d30 100644 --- a/main.c +++ b/main.c @@ -27,17 +27,12 @@ Display *dsply = NULL; Window root; int screen; XFontStruct *font = NULL; -#ifdef XFT XftFont *xftfont = NULL; XftColor xft_detail; -#endif GC string_gc, border_gc, text_gc, active_gc, depressed_gc, inactive_gc, menu_gc, selected_gc, empty_gc; XColor border_col, text_col, active_col, depressed_col, inactive_col, menu_col, selected_col, empty_col; Cursor resize_curs; Atom wm_state, wm_change_state, wm_protos, wm_delete, wm_cmapwins; -#ifdef MWM_HINTS -Atom mwm_hints; -#endif Client *head_client = NULL, *focused_client = NULL, *topmost_client = NULL, *fullscreen_client = NULL; unsigned int in_taskbar = 0; // actually, we don't know yet unsigned int showing_taskbar = 1; @@ -52,10 +47,6 @@ char *opt_menu = DEF_MENU; char *opt_selected = DEF_SELECTED; char *opt_empty = DEF_EMPTY; char *opt_display = NULL; -#ifdef SHAPE -Bool shape; -int shape_event; -#endif unsigned int numlockmask = 0; static void scan_wins(void); @@ -63,203 +54,182 @@ static void setup_display(void); int main(int argc, char **argv) { - int i; - struct sigaction act; - -#define OPT_STR(name, variable) \ - if (strcmp(argv[i], name) == 0 && i + 1 < argc) \ - { \ - variable = argv[++i]; \ - continue; \ - } - - for (i = 1; i < argc; i++) - { - OPT_STR("-font", opt_font) - OPT_STR("-border", opt_border) - OPT_STR("-text", opt_text) - OPT_STR("-active", opt_active) - OPT_STR("-inactive", opt_inactive) - OPT_STR("-menu", opt_menu) - OPT_STR("-selected", opt_selected) - OPT_STR("-empty", opt_empty) - OPT_STR("-display", opt_display) - if (strcmp(argv[i], "-about") == 0) - { - printf("WindowLab " VERSION " (" RELEASEDATE "), Copyright (c) 2001-2009 Nick Gravgaard\nWindowLab comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions; view the LICENCE file for details.\n"); - exit(0); - } - // shouldn't get here; must be a bad option - err("usage:\n windowlab [options]\n\noptions are:\n -font \n -border|-text|-active|-inactive|-menu|-selected|-empty \n -about\n -display "); - return 2; - } - - act.sa_handler = sig_handler; - act.sa_flags = 0; - sigaction(SIGTERM, &act, NULL); - sigaction(SIGINT, &act, NULL); - sigaction(SIGHUP, &act, NULL); - sigaction(SIGCHLD, &act, NULL); - - setup_display(); - get_menuitems(); - make_taskbar(); - scan_wins(); - do_event_loop(); - return 1; // just another brick in the -Wall + int i; + struct sigaction act; + +#define OPT_STR(name, variable) \ + if (strcmp(argv[i], name) == 0 && i + 1 < argc) \ + { \ + variable = argv[++i]; \ + continue; \ + } + + for (i = 1; i < argc; i++) + { + OPT_STR("-font", opt_font) + OPT_STR("-border", opt_border) + OPT_STR("-text", opt_text) + OPT_STR("-active", opt_active) + OPT_STR("-inactive", opt_inactive) + OPT_STR("-menu", opt_menu) + OPT_STR("-selected", opt_selected) + OPT_STR("-empty", opt_empty) + OPT_STR("-display", opt_display) + if (strcmp(argv[i], "-about") == 0) + { + printf("WindowLab " VERSION " (" RELEASEDATE "), Copyright (c) 2001-2009 Nick Gravgaard\nWindowLab comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions; view the LICENCE file for details.\n"); + exit(0); + } + // shouldn't get here; must be a bad option + err("usage:\n windowlab [options]\n\noptions are:\n -font \n -border|-text|-active|-inactive|-menu|-selected|-empty \n -about\n -display "); + return 2; + } + + act.sa_handler = sig_handler; + act.sa_flags = 0; + sigaction(SIGTERM, &act, NULL); + sigaction(SIGINT, &act, NULL); + sigaction(SIGHUP, &act, NULL); + sigaction(SIGCHLD, &act, NULL); + + setup_display(); + get_menuitems(); + make_taskbar(); + scan_wins(); + do_event_loop(); + return 1; // just another brick in the -Wall } static void scan_wins(void) { - unsigned int nwins, i; - Window dummyw1, dummyw2, *wins; - XWindowAttributes attr; - - XQueryTree(dsply, root, &dummyw1, &dummyw2, &wins, &nwins); - for (i = 0; i < nwins; i++) - { - XGetWindowAttributes(dsply, wins[i], &attr); - if (!attr.override_redirect && attr.map_state == IsViewable) - { - make_new_client(wins[i]); - } - } - XFree(wins); + unsigned int nwins, i; + Window dummyw1, dummyw2, *wins; + XWindowAttributes attr; + + XQueryTree(dsply, root, &dummyw1, &dummyw2, &wins, &nwins); + for (i = 0; i < nwins; i++) + { + XGetWindowAttributes(dsply, wins[i], &attr); + if (!attr.override_redirect && attr.map_state == IsViewable) + { + make_new_client(wins[i]); + } + } + XFree(wins); } static void setup_display(void) { - XColor dummyc; - XGCValues gv; - XSetWindowAttributes sattr; - XModifierKeymap *modmap; - int i, j; -#ifdef SHAPE - int dummy; -#endif - - dsply = XOpenDisplay(opt_display); - - if (dsply == NULL) - { - err("can't open display! check your DISPLAY variable."); - exit(1); - } - - XSetErrorHandler(handle_xerror); - screen = DefaultScreen(dsply); - root = RootWindow(dsply, screen); - - wm_state = XInternAtom(dsply, "WM_STATE", False); - wm_change_state = XInternAtom(dsply, "WM_CHANGE_STATE", False); - wm_protos = XInternAtom(dsply, "WM_PROTOCOLS", False); - wm_delete = XInternAtom(dsply, "WM_DELETE_WINDOW", False); - wm_cmapwins = XInternAtom(dsply, "WM_COLORMAP_WINDOWS", False); + XColor dummyc; + XGCValues gv; + XSetWindowAttributes sattr; + XModifierKeymap *modmap; + int i, j; + + dsply = XOpenDisplay(opt_display); + + if (dsply == NULL) + { + err("can't open display! check your DISPLAY variable."); + exit(1); + } + + XSetErrorHandler(handle_xerror); + screen = DefaultScreen(dsply); + root = RootWindow(dsply, screen); + + wm_state = XInternAtom(dsply, "WM_STATE", False); + wm_change_state = XInternAtom(dsply, "WM_CHANGE_STATE", False); + wm_protos = XInternAtom(dsply, "WM_PROTOCOLS", False); + wm_delete = XInternAtom(dsply, "WM_DELETE_WINDOW", False); + wm_cmapwins = XInternAtom(dsply, "WM_COLORMAP_WINDOWS", False); #ifdef MWM_HINTS - mwm_hints = XInternAtom(dsply, _XA_MWM_HINTS, False); -#endif - - XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_border, &border_col, &dummyc); - XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_text, &text_col, &dummyc); - XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_active, &active_col, &dummyc); - XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_inactive, &inactive_col, &dummyc); - XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_menu, &menu_col, &dummyc); - XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_selected, &selected_col, &dummyc); - XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_empty, &empty_col, &dummyc); - - depressed_col.pixel = active_col.pixel; - depressed_col.red = active_col.red - ACTIVE_SHADOW; - depressed_col.green = active_col.green - ACTIVE_SHADOW; - depressed_col.blue = active_col.blue - ACTIVE_SHADOW; - depressed_col.red = depressed_col.red <= (USHRT_MAX - ACTIVE_SHADOW) ? depressed_col.red : 0; - depressed_col.green = depressed_col.green <= (USHRT_MAX - ACTIVE_SHADOW) ? depressed_col.green : 0; - depressed_col.blue = depressed_col.blue <= (USHRT_MAX - ACTIVE_SHADOW) ? depressed_col.blue : 0; - XAllocColor(dsply, DefaultColormap(dsply, screen), &depressed_col); - -#ifdef XFT - xft_detail.color.red = text_col.red; - xft_detail.color.green = text_col.green; - xft_detail.color.blue = text_col.blue; - xft_detail.color.alpha = 0xffff; - xft_detail.pixel = text_col.pixel; - - xftfont = XftFontOpenXlfd(dsply, DefaultScreen(dsply), opt_font); - if (xftfont == NULL) - { - err("font '%s' not found", opt_font); - exit(1); - } -#else - font = XLoadQueryFont(dsply, opt_font); - if (font == NULL) - { - err("XLoadQueryFont(): font '%s' not found", opt_font); - exit(1); - } + mwm_hints = XInternAtom(dsply, _XA_MWM_HINTS, False); #endif -#ifdef SHAPE - shape = XShapeQueryExtension(dsply, &shape_event, &dummy); -#endif - - resize_curs = XCreateFontCursor(dsply, XC_fleur); - - /* find out which modifier is NumLock - we'll use this when grabbing every combination of modifiers we can think of */ - modmap = XGetModifierMapping(dsply); - for (i = 0; i < 8; i++) - { - for (j = 0; j < modmap->max_keypermod; j++) - { - if (modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dsply, XK_Num_Lock)) - { - numlockmask = (1 << i); + XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_border, &border_col, &dummyc); + XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_text, &text_col, &dummyc); + XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_active, &active_col, &dummyc); + XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_inactive, &inactive_col, &dummyc); + XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_menu, &menu_col, &dummyc); + XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_selected, &selected_col, &dummyc); + XAllocNamedColor(dsply, DefaultColormap(dsply, screen), opt_empty, &empty_col, &dummyc); + + depressed_col.pixel = active_col.pixel; + depressed_col.red = active_col.red - ACTIVE_SHADOW; + depressed_col.green = active_col.green - ACTIVE_SHADOW; + depressed_col.blue = active_col.blue - ACTIVE_SHADOW; + depressed_col.red = depressed_col.red <= (USHRT_MAX - ACTIVE_SHADOW) ? depressed_col.red : 0; + depressed_col.green = depressed_col.green <= (USHRT_MAX - ACTIVE_SHADOW) ? depressed_col.green : 0; + depressed_col.blue = depressed_col.blue <= (USHRT_MAX - ACTIVE_SHADOW) ? depressed_col.blue : 0; + XAllocColor(dsply, DefaultColormap(dsply, screen), &depressed_col); + + xft_detail.color.red = text_col.red; + xft_detail.color.green = text_col.green; + xft_detail.color.blue = text_col.blue; + xft_detail.color.alpha = 0xffff; + xft_detail.pixel = text_col.pixel; + + xftfont = XftFontOpenXlfd(dsply, DefaultScreen(dsply), opt_font); + if (xftfont == NULL) + { + err("font '%s' not found", opt_font); + exit(1); + } + + resize_curs = XCreateFontCursor(dsply, XC_fleur); + + /* find out which modifier is NumLock - we'll use this when grabbing every combination of modifiers we can think of */ + modmap = XGetModifierMapping(dsply); + for (i = 0; i < 8; i++) + { + for (j = 0; j < modmap->max_keypermod; j++) + { + if (modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dsply, XK_Num_Lock)) + { + numlockmask = (1 << i); #ifdef DEBUG - fprintf(stderr, "setup_display() : XK_Num_Lock is (1<<0x%02x)\n", i); + fprintf(stderr, "setup_display() : XK_Num_Lock is (1<<0x%02x)\n", i); #endif - } - } - } - XFree(modmap); + } + } + } + XFree(modmap); - gv.function = GXcopy; + gv.function = GXcopy; - gv.foreground = border_col.pixel; - gv.line_width = DEF_BORDERWIDTH; - border_gc = XCreateGC(dsply, root, GCFunction|GCForeground|GCLineWidth, &gv); + gv.foreground = border_col.pixel; + gv.line_width = DEF_BORDERWIDTH; + border_gc = XCreateGC(dsply, root, GCFunction|GCForeground|GCLineWidth, &gv); - gv.foreground = text_col.pixel; - gv.line_width = 1; + gv.foreground = text_col.pixel; + gv.line_width = 1; -#ifdef XFT - text_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); -#else - gv.font = font->fid; - text_gc = XCreateGC(dsply, root, GCFunction|GCForeground|GCFont, &gv); -#endif + text_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); - gv.foreground = active_col.pixel; - active_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); + gv.foreground = active_col.pixel; + active_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); - gv.foreground = depressed_col.pixel; - depressed_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); + gv.foreground = depressed_col.pixel; + depressed_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); - gv.foreground = inactive_col.pixel; - inactive_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); + gv.foreground = inactive_col.pixel; + inactive_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); - gv.foreground = menu_col.pixel; - menu_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); + gv.foreground = menu_col.pixel; + menu_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); - gv.foreground = selected_col.pixel; - selected_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); + gv.foreground = selected_col.pixel; + selected_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); - gv.foreground = empty_col.pixel; - empty_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); + gv.foreground = empty_col.pixel; + empty_gc = XCreateGC(dsply, root, GCFunction|GCForeground, &gv); - sattr.event_mask = ChildMask|ColormapChangeMask|ButtonMask; - XChangeWindowAttributes(dsply, root, CWEventMask, &sattr); + sattr.event_mask = ChildMask|ColormapChangeMask|ButtonMask; + XChangeWindowAttributes(dsply, root, CWEventMask, &sattr); - grab_keysym(root, MODIFIER, KEY_CYCLEPREV); - grab_keysym(root, MODIFIER, KEY_CYCLENEXT); - grab_keysym(root, MODIFIER, KEY_FULLSCREEN); - grab_keysym(root, MODIFIER, KEY_TOGGLEZ); + grab_keysym(root, MODIFIER, KEY_CYCLEPREV); + grab_keysym(root, MODIFIER, KEY_CYCLENEXT); + grab_keysym(root, MODIFIER, KEY_FULLSCREEN); + grab_keysym(root, MODIFIER, KEY_TOGGLEZ); } diff --git a/manage.c b/manage.c index 94d3782..a73a397 100644 --- a/manage.c +++ b/manage.c @@ -25,128 +25,128 @@ static int get_incsize(Client *, unsigned int *, unsigned int *, Rect *, int); void raise_lower(Client *c) { - if (c != NULL) - { - if (c == topmost_client) - { - lower_win(c); - topmost_client = NULL; // lazy but amiwm does similar - } - else - { - raise_win(c); - topmost_client = c; - } - } + if (c != NULL) + { + if (c == topmost_client) + { + lower_win(c); + topmost_client = NULL; // lazy but amiwm does similar + } + else + { + raise_win(c); + topmost_client = c; + } + } } /* increment ignore_unmap here and decrement it in handle_unmap_event in events.c */ void hide(Client *c) { - if (c != NULL) - { - if (!c->hidden) - { - c->ignore_unmap++; - c->hidden = 1; - if (c == topmost_client) - { - topmost_client = NULL; - } - XUnmapWindow(dsply, c->frame); - XUnmapWindow(dsply, c->window); - set_wm_state(c, IconicState); - check_focus(get_prev_focused()); - } - } + if (c != NULL) + { + if (!c->hidden) + { + c->ignore_unmap++; + c->hidden = 1; + if (c == topmost_client) + { + topmost_client = NULL; + } + XUnmapWindow(dsply, c->frame); + XUnmapWindow(dsply, c->window); + set_wm_state(c, IconicState); + check_focus(get_prev_focused()); + } + } } void unhide(Client *c) { - if (c != NULL) - { - if (c->hidden) - { - c->hidden = 0; - topmost_client = c; - XMapWindow(dsply, c->window); - XMapRaised(dsply, c->frame); - set_wm_state(c, NormalState); - } - } + if (c != NULL) + { + if (c->hidden) + { + c->hidden = 0; + topmost_client = c; + XMapWindow(dsply, c->window); + XMapRaised(dsply, c->frame); + set_wm_state(c, NormalState); + } + } } void toggle_fullscreen(Client *c) { - int xoffset, yoffset, maxwinwidth, maxwinheight; - if (c != NULL && !c->trans) - { - if (c == fullscreen_client) // reset to original size - { - c->x = fs_prevdims.x; - c->y = fs_prevdims.y; - c->width = fs_prevdims.width; - c->height = fs_prevdims.height; - XMoveResizeWindow(dsply, c->frame, c->x, c->y - BARHEIGHT(), c->width, c->height + BARHEIGHT()); - XMoveResizeWindow(dsply, c->window, 0, BARHEIGHT(), c->width, c->height); - send_config(c); - fullscreen_client = NULL; - showing_taskbar = 1; - } - else // make fullscreen - { - xoffset = yoffset = 0; - maxwinwidth = DisplayWidth(dsply, screen); - maxwinheight = DisplayHeight(dsply, screen) - BARHEIGHT(); - if (fullscreen_client != NULL) // reset existing fullscreen window to original size - { - fullscreen_client->x = fs_prevdims.x; - fullscreen_client->y = fs_prevdims.y; - fullscreen_client->width = fs_prevdims.width; - fullscreen_client->height = fs_prevdims.height; - XMoveResizeWindow(dsply, fullscreen_client->frame, fullscreen_client->x, fullscreen_client->y - BARHEIGHT(), fullscreen_client->width, fullscreen_client->height + BARHEIGHT()); - XMoveResizeWindow(dsply, fullscreen_client->window, 0, BARHEIGHT(), fullscreen_client->width, fullscreen_client->height); - send_config(fullscreen_client); - } - fs_prevdims.x = c->x; - fs_prevdims.y = c->y; - fs_prevdims.width = c->width; - fs_prevdims.height = c->height; - c->x = 0 - BORDERWIDTH(c); - c->y = BARHEIGHT() - BORDERWIDTH(c); - c->width = maxwinwidth; - c->height = maxwinheight; - if (c->size->flags & PMaxSize || c->size->flags & PResizeInc) - { - if (c->size->flags & PResizeInc) - { - Rect maxwinsize; - maxwinsize.x = xoffset; - maxwinsize.width = maxwinwidth; - maxwinsize.y = yoffset; - maxwinsize.height = maxwinheight; - get_incsize(c, (unsigned int *)&c->size->max_width, (unsigned int *)&c->size->max_height, &maxwinsize, PIXELS); - } - if (c->size->max_width < maxwinwidth) - { - c->width = c->size->max_width; - xoffset = (maxwinwidth - c->width) / 2; - } - if (c->size->max_height < maxwinheight) - { - c->height = c->size->max_height; - yoffset = (maxwinheight - c->height) / 2; - } - } - XMoveResizeWindow(dsply, c->frame, c->x, c->y, maxwinwidth, maxwinheight); - XMoveResizeWindow(dsply, c->window, xoffset, yoffset, c->width, c->height); - send_config(c); - fullscreen_client = c; - showing_taskbar = in_taskbar; - } - redraw_taskbar(); - } + int xoffset, yoffset, maxwinwidth, maxwinheight; + if (c != NULL && !c->trans) + { + if (c == fullscreen_client) // reset to original size + { + c->x = fs_prevdims.x; + c->y = fs_prevdims.y; + c->width = fs_prevdims.width; + c->height = fs_prevdims.height; + XMoveResizeWindow(dsply, c->frame, c->x, c->y - BARHEIGHT(), c->width, c->height + BARHEIGHT()); + XMoveResizeWindow(dsply, c->window, 0, BARHEIGHT(), c->width, c->height); + send_config(c); + fullscreen_client = NULL; + showing_taskbar = 1; + } + else // make fullscreen + { + xoffset = yoffset = 0; + maxwinwidth = DisplayWidth(dsply, screen); + maxwinheight = DisplayHeight(dsply, screen) - BARHEIGHT(); + if (fullscreen_client != NULL) // reset existing fullscreen window to original size + { + fullscreen_client->x = fs_prevdims.x; + fullscreen_client->y = fs_prevdims.y; + fullscreen_client->width = fs_prevdims.width; + fullscreen_client->height = fs_prevdims.height; + XMoveResizeWindow(dsply, fullscreen_client->frame, fullscreen_client->x, fullscreen_client->y - BARHEIGHT(), fullscreen_client->width, fullscreen_client->height + BARHEIGHT()); + XMoveResizeWindow(dsply, fullscreen_client->window, 0, BARHEIGHT(), fullscreen_client->width, fullscreen_client->height); + send_config(fullscreen_client); + } + fs_prevdims.x = c->x; + fs_prevdims.y = c->y; + fs_prevdims.width = c->width; + fs_prevdims.height = c->height; + c->x = 0 - BORDERWIDTH(c); + c->y = BARHEIGHT() - BORDERWIDTH(c); + c->width = maxwinwidth; + c->height = maxwinheight; + if (c->size->flags & PMaxSize || c->size->flags & PResizeInc) + { + if (c->size->flags & PResizeInc) + { + Rect maxwinsize; + maxwinsize.x = xoffset; + maxwinsize.width = maxwinwidth; + maxwinsize.y = yoffset; + maxwinsize.height = maxwinheight; + get_incsize(c, (unsigned int *)&c->size->max_width, (unsigned int *)&c->size->max_height, &maxwinsize, PIXELS); + } + if (c->size->max_width < maxwinwidth) + { + c->width = c->size->max_width; + xoffset = (maxwinwidth - c->width) / 2; + } + if (c->size->max_height < maxwinheight) + { + c->height = c->size->max_height; + yoffset = (maxwinheight - c->height) / 2; + } + } + XMoveResizeWindow(dsply, c->frame, c->x, c->y, maxwinwidth, maxwinheight); + XMoveResizeWindow(dsply, c->window, xoffset, yoffset, c->width, c->height); + send_config(c); + fullscreen_client = c; + showing_taskbar = in_taskbar; + } + redraw_taskbar(); + } } /* The name of this function is a bit misleading: if the client @@ -155,383 +155,379 @@ void toggle_fullscreen(Client *c) void send_wm_delete(Client *c) { - int i, n, found = 0; - Atom *protocols; - - if (XGetWMProtocols(dsply, c->window, &protocols, &n)) - { - for (i = 0; i < n; i++) - { - if (protocols[i] == wm_delete) - { - found++; - } - } - XFree(protocols); - } - if (found) - { - send_xmessage(c->window, wm_protos, wm_delete); - } - else - { - XKillClient(dsply, c->window); - } + int i, n, found = 0; + Atom *protocols; + + if (XGetWMProtocols(dsply, c->window, &protocols, &n)) + { + for (i = 0; i < n; i++) + { + if (protocols[i] == wm_delete) + { + found++; + } + } + XFree(protocols); + } + if (found) + { + send_xmessage(c->window, wm_protos, wm_delete); + } + else + { + XKillClient(dsply, c->window); + } } void move(Client *c) { - XEvent ev; - int old_cx = c->x; - int old_cy = c->y; - int mousex, mousey, dw, dh; - Client *exposed_c; - Rect bounddims; - Window constraint_win; - XSetWindowAttributes pattr; - - dw = DisplayWidth(dsply, screen); - dh = DisplayHeight(dsply, screen); - get_mouse_position(&mousex, &mousey); - - bounddims.x = (mousex - c->x) - BORDERWIDTH(c); - bounddims.width = (dw - bounddims.x - (c->width - bounddims.x)) + 1; - bounddims.y = mousey - c->y; - bounddims.height = (dh - bounddims.y - (c->height - bounddims.y)) + 1; - bounddims.y += (BARHEIGHT() * 2) - BORDERWIDTH(c); - bounddims.height += c->height - ((BARHEIGHT() * 2) - DEF_BORDERWIDTH); - - constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); + XEvent ev; + int old_cx = c->x; + int old_cy = c->y; + int mousex, mousey, dw, dh; + Client *exposed_c; + Rect bounddims; + Window constraint_win; + XSetWindowAttributes pattr; + + dw = DisplayWidth(dsply, screen); + dh = DisplayHeight(dsply, screen); + get_mouse_position(&mousex, &mousey); + + bounddims.x = (mousex - c->x) - BORDERWIDTH(c); + bounddims.width = (dw - bounddims.x - (c->width - bounddims.x)) + 1; + bounddims.y = mousey - c->y; + bounddims.height = (dh - bounddims.y - (c->height - bounddims.y)) + 1; + bounddims.y += (BARHEIGHT() * 2) - BORDERWIDTH(c); + bounddims.height += c->height - ((BARHEIGHT() * 2) - DEF_BORDERWIDTH); + + constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); #ifdef DEBUG - fprintf(stderr, "move() : constraint_win is (%d, %d)-(%d, %d)\n", bounddims.x, bounddims.y, bounddims.x + bounddims.width, bounddims.y + bounddims.height); + fprintf(stderr, "move() : constraint_win is (%d, %d)-(%d, %d)\n", bounddims.x, bounddims.y, bounddims.x + bounddims.width, bounddims.y + bounddims.height); #endif - XMapWindow(dsply, constraint_win); - - if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) - { - XDestroyWindow(dsply, constraint_win); - return; - } - - do - { - XMaskEvent(dsply, ExposureMask|MouseMask, &ev); - switch (ev.type) - { - case Expose: - exposed_c = find_client(ev.xexpose.window, FRAME); - if (exposed_c != NULL) - { - redraw(exposed_c); - } - break; - case MotionNotify: - c->x = old_cx + (ev.xmotion.x - mousex); - c->y = old_cy + (ev.xmotion.y - mousey); - XMoveWindow(dsply, c->frame, c->x, c->y - BARHEIGHT()); - send_config(c); - break; - } - } - while (ev.type != ButtonRelease); - - ungrab(); - XDestroyWindow(dsply, constraint_win); + XMapWindow(dsply, constraint_win); + + if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) + { + XDestroyWindow(dsply, constraint_win); + return; + } + + do + { + XMaskEvent(dsply, ExposureMask|MouseMask, &ev); + switch (ev.type) + { + case Expose: + exposed_c = find_client(ev.xexpose.window, FRAME); + if (exposed_c != NULL) + { + redraw(exposed_c); + } + break; + case MotionNotify: + c->x = old_cx + (ev.xmotion.x - mousex); + c->y = old_cy + (ev.xmotion.y - mousey); + XMoveWindow(dsply, c->frame, c->x, c->y - BARHEIGHT()); + send_config(c); + break; + } + } + while (ev.type != ButtonRelease); + + ungrab(); + XDestroyWindow(dsply, constraint_win); } void resize(Client *c, int x, int y) { - XEvent ev; - Client *exposed_c; - Rect newdims, recalceddims, bounddims; - unsigned int dragging_outwards, dw, dh; - Window constraint_win, resize_win, resizebar_win; - XSetWindowAttributes pattr, resize_pattr, resizebar_pattr; - - if (x > c->x + BORDERWIDTH(c) && x < (c->x + c->width) - BORDERWIDTH(c) && y > (c->y - BARHEIGHT()) + BORDERWIDTH(c) && y < (c->y + c->height) - BORDERWIDTH(c)) - { - // inside the window, dragging outwards - dragging_outwards = 1; - } - else - { - // outside the window, dragging inwards - dragging_outwards = 0; - } - - dw = DisplayWidth(dsply, screen); - dh = DisplayHeight(dsply, screen); - - bounddims.x = 0; - bounddims.width = dw; - bounddims.y = 0; - bounddims.height = dh; - - constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); - XMapWindow(dsply, constraint_win); - - if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, resize_curs, CurrentTime) == GrabSuccess)) - { - XDestroyWindow(dsply, constraint_win); - return; - } - - newdims.x = c->x; - newdims.y = c->y - BARHEIGHT(); - newdims.width = c->width; - newdims.height = c->height + BARHEIGHT(); - - copy_dims(&newdims, &recalceddims); - - // create and map resize window - resize_pattr.override_redirect = True; - resize_pattr.background_pixel = menu_col.pixel; - resize_pattr.border_pixel = border_col.pixel; - resize_pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; - resize_win = XCreateWindow(dsply, root, newdims.x, newdims.y, newdims.width, newdims.height, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &resize_pattr); - XMapRaised(dsply, resize_win); - - resizebar_pattr.override_redirect = True; - resizebar_pattr.background_pixel = active_col.pixel; - resizebar_pattr.border_pixel = border_col.pixel; - resizebar_pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; - resizebar_win = XCreateWindow(dsply, resize_win, -DEF_BORDERWIDTH, -DEF_BORDERWIDTH, newdims.width, BARHEIGHT() - DEF_BORDERWIDTH, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &resizebar_pattr); - XMapRaised(dsply, resizebar_win); - -#ifdef XFT - // temporarily swap drawables in order to draw on the resize window's XFT context - XftDrawChange(c->xftdraw, (Drawable) resizebar_win); -#endif - - // hide real window's frame - XUnmapWindow(dsply, c->frame); - - do - { - XMaskEvent(dsply, ExposureMask|MouseMask, &ev); - switch (ev.type) - { - case Expose: - if (ev.xexpose.window == resizebar_win) - { - write_titletext(c, resizebar_win); - } - else - { - exposed_c = find_client(ev.xexpose.window, FRAME); - if (exposed_c) - { - redraw(exposed_c); - } - } - break; - case MotionNotify: - { - unsigned int in_taskbar = 1, leftedge_changed = 0, rightedge_changed = 0, topedge_changed = 0, bottomedge_changed = 0; - int newwidth, newheight; - // warping the pointer is wrong - wait until it leaves the taskbar - if (ev.xmotion.y < BARHEIGHT()) - { - in_taskbar = 1; - } - else - { - if (in_taskbar == 1) // first time outside taskbar - { - in_taskbar = 0; - bounddims.x = 0; - bounddims.width = dw; - bounddims.y = BARHEIGHT(); - bounddims.height = dh - BARHEIGHT(); - XMoveResizeWindow(dsply, constraint_win, bounddims.x, bounddims.y, bounddims.width, bounddims.height); - in_taskbar = 0; - } - // inside the window, dragging outwards - if (dragging_outwards) - { - if (ev.xmotion.x < newdims.x + BORDERWIDTH(c)) - { - newdims.width += newdims.x + BORDERWIDTH(c) - ev.xmotion.x; - newdims.x = ev.xmotion.x - BORDERWIDTH(c); - leftedge_changed = 1; - } - else if (ev.xmotion.x > newdims.x + newdims.width + BORDERWIDTH(c)) - { - newdims.width = (ev.xmotion.x - newdims.x - BORDERWIDTH(c)) + 1; // add 1 to allow window to be flush with edge of screen - rightedge_changed = 1; - } - if (ev.xmotion.y < newdims.y + BORDERWIDTH(c)) - { - newdims.height += newdims.y + BORDERWIDTH(c) - ev.xmotion.y; - newdims.y = ev.xmotion.y - BORDERWIDTH(c); - topedge_changed = 1; - } - else if (ev.xmotion.y > newdims.y + newdims.height + BORDERWIDTH(c)) - { - newdims.height = (ev.xmotion.y - newdims.y - BORDERWIDTH(c)) + 1; // add 1 to allow window to be flush with edge of screen - bottomedge_changed = 1; - } - } - // outside the window, dragging inwards - else - { - unsigned int above_win, below_win, leftof_win, rightof_win; - unsigned int in_win; - - above_win = (ev.xmotion.y < newdims.y + BORDERWIDTH(c)); - below_win = (ev.xmotion.y > newdims.y + newdims.height + BORDERWIDTH(c)); - leftof_win = (ev.xmotion.x < newdims.x + BORDERWIDTH(c)); - rightof_win = (ev.xmotion.x > newdims.x + newdims.width + BORDERWIDTH(c)); - - in_win = ((!above_win) && (!below_win) && (!leftof_win) && (!rightof_win)); - - if (in_win) - { - unsigned int from_left, from_right, from_top, from_bottom; - from_left = ev.xmotion.x - newdims.x - BORDERWIDTH(c); - from_right = newdims.x + newdims.width + BORDERWIDTH(c) - ev.xmotion.x; - from_top = ev.xmotion.y - newdims.y - BORDERWIDTH(c); - from_bottom = newdims.y + newdims.height + BORDERWIDTH(c) - ev.xmotion.y; - if (from_left < from_right && from_left < from_top && from_left < from_bottom) - { - newdims.width -= ev.xmotion.x - newdims.x - BORDERWIDTH(c); - newdims.x = ev.xmotion.x - BORDERWIDTH(c); - leftedge_changed = 1; - } - else if (from_right < from_top && from_right < from_bottom) - { - newdims.width = ev.xmotion.x - newdims.x - BORDERWIDTH(c); - rightedge_changed = 1; - } - else if (from_top < from_bottom) - { - newdims.height -= ev.xmotion.y - newdims.y - BORDERWIDTH(c); - newdims.y = ev.xmotion.y - BORDERWIDTH(c); - topedge_changed = 1; - } - else - { - newdims.height = ev.xmotion.y - newdims.y - BORDERWIDTH(c); - bottomedge_changed = 1; - } - } - } - // coords have changed - if (leftedge_changed || rightedge_changed || topedge_changed || bottomedge_changed) - { - copy_dims(&newdims, &recalceddims); - recalceddims.height -= BARHEIGHT(); - - if (get_incsize(c, (unsigned int *)&newwidth, (unsigned int *)&newheight, &recalceddims, PIXELS)) - { - if (leftedge_changed) - { - recalceddims.x = (recalceddims.x + recalceddims.width) - newwidth; - recalceddims.width = newwidth; - } - else if (rightedge_changed) - { - recalceddims.width = newwidth; - } - - if (topedge_changed) - { - recalceddims.y = (recalceddims.y + recalceddims.height) - newheight; - recalceddims.height = newheight; - } - else if (bottomedge_changed) - { - recalceddims.height = newheight; - } - } - - recalceddims.height += BARHEIGHT(); - limit_size(c, &recalceddims); - - XMoveResizeWindow(dsply, resize_win, recalceddims.x, recalceddims.y, recalceddims.width, recalceddims.height); - XResizeWindow(dsply, resizebar_win, recalceddims.width, BARHEIGHT() - DEF_BORDERWIDTH); - } - } - } - break; - } - } - while (ev.type != ButtonRelease); - - XUngrabServer(dsply); - ungrab(); - c->x = recalceddims.x; - c->y = recalceddims.y + BARHEIGHT(); - c->width = recalceddims.width; - c->height = recalceddims.height - BARHEIGHT(); - - XMoveResizeWindow(dsply, c->frame, c->x, c->y - BARHEIGHT(), c->width, c->height + BARHEIGHT()); - XResizeWindow(dsply, c->window, c->width, c->height); - - // unhide real window's frame - XMapWindow(dsply, c->frame); - - XSetInputFocus(dsply, c->window, RevertToNone, CurrentTime); - - send_config(c); - XDestroyWindow(dsply, constraint_win); - -#ifdef XFT - // reset the drawable - XftDrawChange(c->xftdraw, (Drawable) c->frame); -#endif - - XDestroyWindow(dsply, resizebar_win); - XDestroyWindow(dsply, resize_win); + XEvent ev; + Client *exposed_c; + Rect newdims, recalceddims, bounddims; + unsigned int dragging_outwards, dw, dh; + Window constraint_win, resize_win, resizebar_win; + XSetWindowAttributes pattr, resize_pattr, resizebar_pattr; + + if (x > c->x + BORDERWIDTH(c) && x < (c->x + c->width) - BORDERWIDTH(c) && y > (c->y - BARHEIGHT()) + BORDERWIDTH(c) && y < (c->y + c->height) - BORDERWIDTH(c)) + { + // inside the window, dragging outwards + dragging_outwards = 1; + } + else + { + // outside the window, dragging inwards + dragging_outwards = 0; + } + + dw = DisplayWidth(dsply, screen); + dh = DisplayHeight(dsply, screen); + + bounddims.x = 0; + bounddims.width = dw; + bounddims.y = 0; + bounddims.height = dh; + + constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); + XMapWindow(dsply, constraint_win); + + if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, resize_curs, CurrentTime) == GrabSuccess)) + { + XDestroyWindow(dsply, constraint_win); + return; + } + + newdims.x = c->x; + newdims.y = c->y - BARHEIGHT(); + newdims.width = c->width; + newdims.height = c->height + BARHEIGHT(); + + copy_dims(&newdims, &recalceddims); + + // create and map resize window + resize_pattr.override_redirect = True; + resize_pattr.background_pixel = menu_col.pixel; + resize_pattr.border_pixel = border_col.pixel; + resize_pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; + resize_win = XCreateWindow(dsply, root, newdims.x, newdims.y, newdims.width, newdims.height, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &resize_pattr); + XMapRaised(dsply, resize_win); + + resizebar_pattr.override_redirect = True; + resizebar_pattr.background_pixel = active_col.pixel; + resizebar_pattr.border_pixel = border_col.pixel; + resizebar_pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; + resizebar_win = XCreateWindow(dsply, resize_win, -DEF_BORDERWIDTH, -DEF_BORDERWIDTH, newdims.width, BARHEIGHT() - DEF_BORDERWIDTH, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &resizebar_pattr); + XMapRaised(dsply, resizebar_win); + + // temporarily swap drawables in order to draw on the resize window's XFT context + XftDrawChange(c->xftdraw, (Drawable) resizebar_win); + + // hide real window's frame + XUnmapWindow(dsply, c->frame); + + do + { + XMaskEvent(dsply, ExposureMask|MouseMask, &ev); + switch (ev.type) + { + case Expose: + if (ev.xexpose.window == resizebar_win) + { + write_titletext(c, resizebar_win); + } + else + { + exposed_c = find_client(ev.xexpose.window, FRAME); + if (exposed_c) + { + redraw(exposed_c); + } + } + break; + case MotionNotify: + { + unsigned int in_taskbar = 1, leftedge_changed = 0, rightedge_changed = 0, topedge_changed = 0, bottomedge_changed = 0; + int newwidth, newheight; + // warping the pointer is wrong - wait until it leaves the taskbar + if (ev.xmotion.y < BARHEIGHT()) + { + in_taskbar = 1; + } + else + { + if (in_taskbar == 1) // first time outside taskbar + { + in_taskbar = 0; + bounddims.x = 0; + bounddims.width = dw; + bounddims.y = BARHEIGHT(); + bounddims.height = dh - BARHEIGHT(); + XMoveResizeWindow(dsply, constraint_win, bounddims.x, bounddims.y, bounddims.width, bounddims.height); + in_taskbar = 0; + } + // inside the window, dragging outwards + if (dragging_outwards) + { + if (ev.xmotion.x < newdims.x + BORDERWIDTH(c)) + { + newdims.width += newdims.x + BORDERWIDTH(c) - ev.xmotion.x; + newdims.x = ev.xmotion.x - BORDERWIDTH(c); + leftedge_changed = 1; + } + else if (ev.xmotion.x > newdims.x + newdims.width + BORDERWIDTH(c)) + { + newdims.width = (ev.xmotion.x - newdims.x - BORDERWIDTH(c)) + 1; // add 1 to allow window to be flush with edge of screen + rightedge_changed = 1; + } + if (ev.xmotion.y < newdims.y + BORDERWIDTH(c)) + { + newdims.height += newdims.y + BORDERWIDTH(c) - ev.xmotion.y; + newdims.y = ev.xmotion.y - BORDERWIDTH(c); + topedge_changed = 1; + } + else if (ev.xmotion.y > newdims.y + newdims.height + BORDERWIDTH(c)) + { + newdims.height = (ev.xmotion.y - newdims.y - BORDERWIDTH(c)) + 1; // add 1 to allow window to be flush with edge of screen + bottomedge_changed = 1; + } + } + // outside the window, dragging inwards + else + { + unsigned int above_win, below_win, leftof_win, rightof_win; + unsigned int in_win; + + above_win = (ev.xmotion.y < newdims.y + BORDERWIDTH(c)); + below_win = (ev.xmotion.y > newdims.y + newdims.height + BORDERWIDTH(c)); + leftof_win = (ev.xmotion.x < newdims.x + BORDERWIDTH(c)); + rightof_win = (ev.xmotion.x > newdims.x + newdims.width + BORDERWIDTH(c)); + + in_win = ((!above_win) && (!below_win) && (!leftof_win) && (!rightof_win)); + + if (in_win) + { + unsigned int from_left, from_right, from_top, from_bottom; + from_left = ev.xmotion.x - newdims.x - BORDERWIDTH(c); + from_right = newdims.x + newdims.width + BORDERWIDTH(c) - ev.xmotion.x; + from_top = ev.xmotion.y - newdims.y - BORDERWIDTH(c); + from_bottom = newdims.y + newdims.height + BORDERWIDTH(c) - ev.xmotion.y; + if (from_left < from_right && from_left < from_top && from_left < from_bottom) + { + newdims.width -= ev.xmotion.x - newdims.x - BORDERWIDTH(c); + newdims.x = ev.xmotion.x - BORDERWIDTH(c); + leftedge_changed = 1; + } + else if (from_right < from_top && from_right < from_bottom) + { + newdims.width = ev.xmotion.x - newdims.x - BORDERWIDTH(c); + rightedge_changed = 1; + } + else if (from_top < from_bottom) + { + newdims.height -= ev.xmotion.y - newdims.y - BORDERWIDTH(c); + newdims.y = ev.xmotion.y - BORDERWIDTH(c); + topedge_changed = 1; + } + else + { + newdims.height = ev.xmotion.y - newdims.y - BORDERWIDTH(c); + bottomedge_changed = 1; + } + } + } + // coords have changed + if (leftedge_changed || rightedge_changed || topedge_changed || bottomedge_changed) + { + copy_dims(&newdims, &recalceddims); + recalceddims.height -= BARHEIGHT(); + + if (get_incsize(c, (unsigned int *)&newwidth, (unsigned int *)&newheight, &recalceddims, PIXELS)) + { + if (leftedge_changed) + { + recalceddims.x = (recalceddims.x + recalceddims.width) - newwidth; + recalceddims.width = newwidth; + } + else if (rightedge_changed) + { + recalceddims.width = newwidth; + } + + if (topedge_changed) + { + recalceddims.y = (recalceddims.y + recalceddims.height) - newheight; + recalceddims.height = newheight; + } + else if (bottomedge_changed) + { + recalceddims.height = newheight; + } + } + + recalceddims.height += BARHEIGHT(); + limit_size(c, &recalceddims); + + XMoveResizeWindow(dsply, resize_win, recalceddims.x, recalceddims.y, recalceddims.width, recalceddims.height); + XResizeWindow(dsply, resizebar_win, recalceddims.width, BARHEIGHT() - DEF_BORDERWIDTH); + } + } + } + break; + } + } + while (ev.type != ButtonRelease); + + XUngrabServer(dsply); + ungrab(); + c->x = recalceddims.x; + c->y = recalceddims.y + BARHEIGHT(); + c->width = recalceddims.width; + c->height = recalceddims.height - BARHEIGHT(); + + XMoveResizeWindow(dsply, c->frame, c->x, c->y - BARHEIGHT(), c->width, c->height + BARHEIGHT()); + XResizeWindow(dsply, c->window, c->width, c->height); + + // unhide real window's frame + XMapWindow(dsply, c->frame); + + XSetInputFocus(dsply, c->window, RevertToNone, CurrentTime); + + send_config(c); + XDestroyWindow(dsply, constraint_win); + + // reset the drawable + XftDrawChange(c->xftdraw, (Drawable) c->frame); + + XDestroyWindow(dsply, resizebar_win); + XDestroyWindow(dsply, resize_win); } static void limit_size(Client *c, Rect *newdims) { - int dw, dh; - dw = DisplayWidth(dsply, screen); - dh = DisplayHeight(dsply, screen); - - if (c->size->flags & PMinSize) - { - if (newdims->width < c->size->min_width) - { - newdims->width = c->size->min_width; - } - if (newdims->height < c->size->min_height) - { - newdims->height = c->size->min_height; - } - } - - if (c->size->flags & PMaxSize) - { - if (newdims->width > c->size->max_width) - { - newdims->width = c->size->max_width; - } - if (newdims->height > c->size->max_height) - { - newdims->height = c->size->max_height; - } - } - - if (newdims->width < MINWINWIDTH) - { - newdims->width = MINWINWIDTH; - } - if (newdims->height < MINWINHEIGHT) - { - newdims->height = MINWINHEIGHT; - } - - if (newdims->width > dw) - { - newdims->width = dw; - } - if (newdims->height > (dh - BARHEIGHT())) - { - newdims->height = (dh - BARHEIGHT()); - } + int dw, dh; + dw = DisplayWidth(dsply, screen); + dh = DisplayHeight(dsply, screen); + + if (c->size->flags & PMinSize) + { + if (newdims->width < c->size->min_width) + { + newdims->width = c->size->min_width; + } + if (newdims->height < c->size->min_height) + { + newdims->height = c->size->min_height; + } + } + + if (c->size->flags & PMaxSize) + { + if (newdims->width > c->size->max_width) + { + newdims->width = c->size->max_width; + } + if (newdims->height > c->size->max_height) + { + newdims->height = c->size->max_height; + } + } + + if (newdims->width < MINWINWIDTH) + { + newdims->width = MINWINWIDTH; + } + if (newdims->height < MINWINHEIGHT) + { + newdims->height = MINWINHEIGHT; + } + + if (newdims->width > dw) + { + newdims->width = dw; + } + if (newdims->height > (dh - BARHEIGHT())) + { + newdims->height = (dh - BARHEIGHT()); + } } /* If the window in question has a ResizeInc int, then it wants to be @@ -541,54 +537,44 @@ static void limit_size(Client *c, Rect *newdims) static int get_incsize(Client *c, unsigned int *x_ret, unsigned int *y_ret, Rect *newdims, int mode) { - int basex, basey; - if (c->size->flags & PResizeInc) - { - basex = (c->size->flags & PBaseSize) ? c->size->base_width : (c->size->flags & PMinSize) ? c->size->min_width : 0; - basey = (c->size->flags & PBaseSize) ? c->size->base_height : (c->size->flags & PMinSize) ? c->size->min_height : 0; - // work around broken apps that set their resize increments to 0 - if (mode == PIXELS) - { - if (c->size->width_inc != 0) - { - *x_ret = newdims->width - ((newdims->width - basex) % c->size->width_inc); - } - if (c->size->height_inc != 0) - { - *y_ret = newdims->height - ((newdims->height - basey) % c->size->height_inc); - } - } - else // INCREMENTS - { - if (c->size->width_inc != 0) - { - *x_ret = (newdims->width - basex) / c->size->width_inc; - } - if (c->size->height_inc != 0) - { - *y_ret = (newdims->height - basey) / c->size->height_inc; - } - } - return 1; - } - return 0; + int basex, basey; + if (c->size->flags & PResizeInc) + { + basex = (c->size->flags & PBaseSize) ? c->size->base_width : (c->size->flags & PMinSize) ? c->size->min_width : 0; + basey = (c->size->flags & PBaseSize) ? c->size->base_height : (c->size->flags & PMinSize) ? c->size->min_height : 0; + // work around broken apps that set their resize increments to 0 + if (mode == PIXELS) + { + if (c->size->width_inc != 0) + { + *x_ret = newdims->width - ((newdims->width - basex) % c->size->width_inc); + } + if (c->size->height_inc != 0) + { + *y_ret = newdims->height - ((newdims->height - basey) % c->size->height_inc); + } + } + else // INCREMENTS + { + if (c->size->width_inc != 0) + { + *x_ret = (newdims->width - basex) / c->size->width_inc; + } + if (c->size->height_inc != 0) + { + *y_ret = (newdims->height - basey) / c->size->height_inc; + } + } + return 1; + } + return 0; } void write_titletext(Client *c, Window bar_win) { -#ifdef MWM_HINTS - if (!c->has_title) - { - return; - } -#endif - if (!c->trans && c->name != NULL) - { -#ifdef XFT - (void) bar_win; // fixes a warning - XftDrawString8(c->xftdraw, &xft_detail, xftfont, SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name)); -#else - XDrawString(dsply, bar_win, text_gc, SPACE, SPACE + font->ascent, c->name, strlen(c->name)); -#endif - } + if (!c->trans && c->name != NULL) + { + (void) bar_win; // fixes a warning + XftDrawString8(c->xftdraw, &xft_detail, xftfont, SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name)); + } } diff --git a/menufile.c b/menufile.c index a2feac2..4e3995c 100644 --- a/menufile.c +++ b/menufile.c @@ -27,178 +27,172 @@ static int parseline(char *, char *, char *); MenuItem *menuitems = NULL; unsigned int num_menuitems; -#ifdef XFT XGlyphInfo extents; -#endif void get_menuitems(void) { - unsigned int i, button_startx = 0; - FILE *menufile = NULL; - char menurcpath[PATH_MAX], *c; - extern int errno; + unsigned int i, button_startx = 0; + FILE *menufile = NULL; + char menurcpath[PATH_MAX], *c; + extern int errno; - menuitems = (MenuItem *)malloc(MAX_MENUITEMS_SIZE); - if (menuitems == NULL) - { - err("Unable to allocate menu items array."); - return; - } - memset(menuitems, 0, MAX_MENUITEMS_SIZE); + menuitems = (MenuItem *)malloc(MAX_MENUITEMS_SIZE); + if (menuitems == NULL) + { + err("Unable to allocate menu items array."); + return; + } + memset(menuitems, 0, MAX_MENUITEMS_SIZE); - snprintf(menurcpath, sizeof(menurcpath), "%s/.windowlab/windowlab.menurc", getenv("HOME")); + snprintf(menurcpath, sizeof(menurcpath), "%s/.windowlab/windowlab.menurc", getenv("HOME")); #ifdef DEBUG - printf("trying to open: %s\n", menurcpath); + printf("trying to open: %s\n", menurcpath); #endif - if ((menufile = fopen(menurcpath, "r")) == NULL) - { - ssize_t len; - // get location of the executable - if ((len = readlink("/proc/self/exe", menurcpath, PATH_MAX - 1)) == -1) - { - err("readlink() /proc/self/exe failed: %s\n", strerror(errno)); - menurcpath[0] = '.'; - menurcpath[1] = '\0'; - } - else - { - // insert null to end the file path properly - menurcpath[len] = '\0'; - } - if ((c = strrchr(menurcpath, '/')) != NULL) - { - *c = '\0'; - } - if ((c = strrchr(menurcpath, '/')) != NULL) - { - *c = '\0'; - } - strncat(menurcpath, "/etc/windowlab.menurc", PATH_MAX - strlen(menurcpath) - 1); + if ((menufile = fopen(menurcpath, "r")) == NULL) + { + ssize_t len; + // get location of the executable + if ((len = readlink("/proc/self/exe", menurcpath, PATH_MAX - 1)) == -1) + { + err("readlink() /proc/self/exe failed: %s\n", strerror(errno)); + menurcpath[0] = '.'; + menurcpath[1] = '\0'; + } + else + { + // insert null to end the file path properly + menurcpath[len] = '\0'; + } + if ((c = strrchr(menurcpath, '/')) != NULL) + { + *c = '\0'; + } + if ((c = strrchr(menurcpath, '/')) != NULL) + { + *c = '\0'; + } + strncat(menurcpath, "/etc/windowlab.menurc", PATH_MAX - strlen(menurcpath) - 1); #ifdef DEBUG - printf("trying to open: %s\n", menurcpath); + printf("trying to open: %s\n", menurcpath); #endif - if ((menufile = fopen(menurcpath, "r")) == NULL) - { + if ((menufile = fopen(menurcpath, "r")) == NULL) + { #ifdef DEBUG - printf("trying to open: %s\n", DEF_MENURC); + printf("trying to open: %s\n", DEF_MENURC); #endif - menufile = fopen(DEF_MENURC, "r"); - } - } - if (menufile != NULL) - { - num_menuitems = 0; - while ((!feof(menufile)) && (!ferror(menufile)) && (num_menuitems < MAX_MENUITEMS)) - { - char menustr[STR_SIZE] = ""; - fgets(menustr, STR_SIZE, menufile); - if (strlen(menustr) != 0) - { - char *pmenustr = menustr; - while (pmenustr[0] == ' ' || pmenustr[0] == '\t') - { - pmenustr++; - } - if (pmenustr[0] != '#') - { - char labelstr[STR_SIZE] = "", commandstr[STR_SIZE] = ""; - if (parseline(pmenustr, labelstr, commandstr)) - { - menuitems[num_menuitems].label = (char *)malloc(strlen(labelstr) + 1); - menuitems[num_menuitems].command = (char *)malloc(strlen(commandstr) + 1); - strcpy(menuitems[num_menuitems].label, labelstr); - strcpy(menuitems[num_menuitems].command, commandstr); - num_menuitems++; - } - } - } - } - fclose(menufile); - } - else - { - // one menu item - xterm - err("can't find ~/.windowlab/windowlab.menurc, %s or %s\n", menurcpath, DEF_MENURC); - menuitems[0].command = (char *)malloc(strlen(NO_MENU_COMMAND) + 1); - strcpy(menuitems[0].command, NO_MENU_COMMAND); - menuitems[0].label = (char *)malloc(strlen(NO_MENU_LABEL) + 1); - strcpy(menuitems[0].label, NO_MENU_LABEL); - num_menuitems = 1; - } + menufile = fopen(DEF_MENURC, "r"); + } + } + if (menufile != NULL) + { + num_menuitems = 0; + while ((!feof(menufile)) && (!ferror(menufile)) && (num_menuitems < MAX_MENUITEMS)) + { + char menustr[STR_SIZE] = ""; + fgets(menustr, STR_SIZE, menufile); + if (strlen(menustr) != 0) + { + char *pmenustr = menustr; + while (pmenustr[0] == ' ' || pmenustr[0] == '\t') + { + pmenustr++; + } + if (pmenustr[0] != '#') + { + char labelstr[STR_SIZE] = "", commandstr[STR_SIZE] = ""; + if (parseline(pmenustr, labelstr, commandstr)) + { + menuitems[num_menuitems].label = (char *)malloc(strlen(labelstr) + 1); + menuitems[num_menuitems].command = (char *)malloc(strlen(commandstr) + 1); + strcpy(menuitems[num_menuitems].label, labelstr); + strcpy(menuitems[num_menuitems].command, commandstr); + num_menuitems++; + } + } + } + } + fclose(menufile); + } + else + { + // one menu item - xterm + err("can't find ~/.windowlab/windowlab.menurc, %s or %s\n", menurcpath, DEF_MENURC); + menuitems[0].command = (char *)malloc(strlen(NO_MENU_COMMAND) + 1); + strcpy(menuitems[0].command, NO_MENU_COMMAND); + menuitems[0].label = (char *)malloc(strlen(NO_MENU_LABEL) + 1); + strcpy(menuitems[0].label, NO_MENU_LABEL); + num_menuitems = 1; + } - for (i = 0; i < num_menuitems; i++) - { - menuitems[i].x = button_startx; -#ifdef XFT - XftTextExtents8(dsply, xftfont, (unsigned char *)menuitems[i].label, strlen(menuitems[i].label), &extents); - menuitems[i].width = extents.width + (SPACE * 4); -#else - menuitems[i].width = XTextWidth(font, menuitems[i].label, strlen(menuitems[i].label)) + (SPACE * 4); -#endif - button_startx += menuitems[i].width + 1; - } - // menu items have been built - do_menuitems = 0; + for (i = 0; i < num_menuitems; i++) + { + menuitems[i].x = button_startx; + XftTextExtents8(dsply, xftfont, (unsigned char *)menuitems[i].label, strlen(menuitems[i].label), &extents); + menuitems[i].width = extents.width + (SPACE * 4); + button_startx += menuitems[i].width + 1; + } + // menu items have been built + do_menuitems = 0; } int parseline(char *menustr, char *labelstr, char *commandstr) { - int success = 0; - int menustrlen = strlen(menustr); - char *ptemp = NULL; - char *menustrcpy = (char *)malloc(menustrlen + 1); + int success = 0; + int menustrlen = strlen(menustr); + char *ptemp = NULL; + char *menustrcpy = (char *)malloc(menustrlen + 1); - if (menustrcpy == NULL) - { - return 0; - } + if (menustrcpy == NULL) + { + return 0; + } - strcpy(menustrcpy, menustr); - ptemp = strtok(menustrcpy, ":"); + strcpy(menustrcpy, menustr); + ptemp = strtok(menustrcpy, ":"); - if (ptemp != NULL) - { - strcpy(labelstr, ptemp); - ptemp = strtok(NULL, "\n"); - if (ptemp != NULL) // right of ':' is not empty - { - while (*ptemp == ' ' || *ptemp == '\t') - { - ptemp++; - } - if (*ptemp != '\0' && *ptemp != '\r' && *ptemp != '\n') - { - strcpy(commandstr, ptemp); - success = 1; - } - } - } - if (menustrcpy != NULL) - { - free(menustrcpy); - } - return success; + if (ptemp != NULL) + { + strcpy(labelstr, ptemp); + ptemp = strtok(NULL, "\n"); + if (ptemp != NULL) // right of ':' is not empty + { + while (*ptemp == ' ' || *ptemp == '\t') + { + ptemp++; + } + if (*ptemp != '\0' && *ptemp != '\r' && *ptemp != '\n') + { + strcpy(commandstr, ptemp); + success = 1; + } + } + } + if (menustrcpy != NULL) + { + free(menustrcpy); + } + return success; } void free_menuitems(void) { - unsigned int i; - if (menuitems != NULL) - { - for (i = 0; i < num_menuitems; i++) - { - if (menuitems[i].label != NULL) - { - free(menuitems[i].label); - menuitems[i].label = NULL; - } - if (menuitems[i].command != NULL) - { - free(menuitems[i].command); - menuitems[i].command = NULL; - } - } - free(menuitems); - menuitems = NULL; - } + unsigned int i; + if (menuitems != NULL) + { + for (i = 0; i < num_menuitems; i++) + { + if (menuitems[i].label != NULL) + { + free(menuitems[i].label); + menuitems[i].label = NULL; + } + if (menuitems[i].command != NULL) + { + free(menuitems[i].command); + menuitems[i].command = NULL; + } + } + free(menuitems); + menuitems = NULL; + } } diff --git a/misc.c b/misc.c index 9ca790b..7399c85 100644 --- a/misc.c +++ b/misc.c @@ -29,134 +29,134 @@ static void quit_nicely(void); void err(const char *fmt, ...) { - va_list argp; + va_list argp; - fprintf(stderr, "windowlab: "); - va_start(argp, fmt); - vfprintf(stderr, fmt, argp); - va_end(argp); - fprintf(stderr, "\n"); + fprintf(stderr, "windowlab: "); + va_start(argp, fmt); + vfprintf(stderr, fmt, argp); + va_end(argp); + fprintf(stderr, "\n"); } void fork_exec(char *cmd) { - char *envshell, *envshellname; - pid_t pid = fork(); - - switch (pid) - { - case 0: - setsid(); - envshell = getenv("SHELL"); - if (envshell == NULL) - { - envshell = "/bin/sh"; - } - envshellname = strrchr(envshell, '/'); - if (envshellname == NULL) - { - envshellname = envshell; - } - else - { - /* move to the character after the slash */ - envshellname++; - } - execlp(envshell, envshellname, "-c", cmd, NULL); - err("exec failed, cleaning up child"); - exit(1); - break; - case -1: - err("can't fork"); - break; - } + char *envshell, *envshellname; + pid_t pid = fork(); + + switch (pid) + { + case 0: + setsid(); + envshell = getenv("SHELL"); + if (envshell == NULL) + { + envshell = "/bin/sh"; + } + envshellname = strrchr(envshell, '/'); + if (envshellname == NULL) + { + envshellname = envshell; + } + else + { + /* move to the character after the slash */ + envshellname++; + } + execlp(envshell, envshellname, "-c", cmd, NULL); + err("exec failed, cleaning up child"); + exit(1); + break; + case -1: + err("can't fork"); + break; + } } void sig_handler(int signal) { - pid_t pid; - int status; - - switch (signal) - { - case SIGINT: - case SIGTERM: - quit_nicely(); - break; - case SIGHUP: - do_menuitems = 1; - break; - case SIGCHLD: - while ((pid = waitpid(-1, &status, WNOHANG)) != 0) - { - if ((pid == -1) && (errno != EINTR)) - { - break; - } - else - { - continue; - } - } - break; - } + pid_t pid; + int status; + + switch (signal) + { + case SIGINT: + case SIGTERM: + quit_nicely(); + break; + case SIGHUP: + do_menuitems = 1; + break; + case SIGCHLD: + while ((pid = waitpid(-1, &status, WNOHANG)) != 0) + { + if ((pid == -1) && (errno != EINTR)) + { + break; + } + else + { + continue; + } + } + break; + } } int handle_xerror(Display *dsply, XErrorEvent *e) { - Client *c = find_client(e->resourceid, WINDOW); - - if (e->error_code == BadAccess && e->resourceid == root) - { - err("root window unavailable (maybe another wm is running?)"); - exit(1); - } - else - { - char msg[255]; - XGetErrorText(dsply, e->error_code, msg, sizeof msg); - err("X error (%#lx): %s", e->resourceid, msg); - } - - if (c != NULL) - { - remove_client(c, WITHDRAW); - } - return 0; + Client *c = find_client(e->resourceid, WINDOW); + + if (e->error_code == BadAccess && e->resourceid == root) + { + err("root window unavailable (maybe another wm is running?)"); + exit(1); + } + else + { + char msg[255]; + XGetErrorText(dsply, e->error_code, msg, sizeof msg); + err("X error (%#lx): %s", e->resourceid, msg); + } + + if (c != NULL) + { + remove_client(c, WITHDRAW); + } + return 0; } /* Ick. Argh. You didn't see this function. */ int ignore_xerror(Display *dsply, XErrorEvent *e) { - (void) dsply; - (void) e; - return 0; + (void) dsply; + (void) e; + return 0; } /* Currently, only send_wm_delete uses this one... */ int send_xmessage(Window w, Atom a, long x) { - XClientMessageEvent e; + XClientMessageEvent e; - e.type = ClientMessage; - e.window = w; - e.message_type = a; - e.format = 32; - e.data.l[0] = x; - e.data.l[1] = CurrentTime; + e.type = ClientMessage; + e.window = w; + e.message_type = a; + e.format = 32; + e.data.l[0] = x; + e.data.l[1] = CurrentTime; - return XSendEvent(dsply, w, False, NoEventMask, (XEvent *)&e); + return XSendEvent(dsply, w, False, NoEventMask, (XEvent *)&e); } void get_mouse_position(int *x, int *y) { - Window mouse_root, mouse_win; - int win_x, win_y; - unsigned int mask; + Window mouse_root, mouse_win; + int win_x, win_y; + unsigned int mask; - XQueryPointer(dsply, root, &mouse_root, &mouse_win, x, y, &win_x, &win_y, &mask); + XQueryPointer(dsply, root, &mouse_root, &mouse_win, x, y, &win_x, &win_y, &mask); } /* If this is the fullscreen client we don't take BARHEIGHT() into account @@ -164,92 +164,92 @@ void get_mouse_position(int *x, int *y) void fix_position(Client *c) { - int xmax = DisplayWidth(dsply, screen); - int ymax = DisplayHeight(dsply, screen); - int titlebarheight; + int xmax = DisplayWidth(dsply, screen); + int ymax = DisplayHeight(dsply, screen); + int titlebarheight; #ifdef DEBUG - fprintf(stderr, "fix_position(): client was (%d, %d)-(%d, %d)\n", c->x, c->y, c->x + c->width, c->y + c->height); + fprintf(stderr, "fix_position(): client was (%d, %d)-(%d, %d)\n", c->x, c->y, c->x + c->width, c->y + c->height); #endif - - titlebarheight = (fullscreen_client == c) ? 0 : BARHEIGHT(); - - if (c->width < MINWINWIDTH) - { - c->width = MINWINWIDTH; - } - if (c->height < MINWINHEIGHT) - { - c->height = MINWINHEIGHT; - } - - if (c->width > xmax) - { - c->width = xmax; - } - if (c->height + (BARHEIGHT() + titlebarheight) > ymax) - { - c->height = ymax - (BARHEIGHT() + titlebarheight); - } - - if (c->x < 0) - { - c->x = 0; - } - if (c->y < BARHEIGHT()) - { - c->y = BARHEIGHT(); - } - - if (c->x + c->width + BORDERWIDTH(c) >= xmax) - { - c->x = xmax - c->width; - } - if (c->y + c->height + BARHEIGHT() >= ymax) - { - c->y = (ymax - c->height) - BARHEIGHT(); - } + + titlebarheight = (fullscreen_client == c) ? 0 : BARHEIGHT(); + + if (c->width < MINWINWIDTH) + { + c->width = MINWINWIDTH; + } + if (c->height < MINWINHEIGHT) + { + c->height = MINWINHEIGHT; + } + + if (c->width > xmax) + { + c->width = xmax; + } + if (c->height + (BARHEIGHT() + titlebarheight) > ymax) + { + c->height = ymax - (BARHEIGHT() + titlebarheight); + } + + if (c->x < 0) + { + c->x = 0; + } + if (c->y < BARHEIGHT()) + { + c->y = BARHEIGHT(); + } + + if (c->x + c->width + BORDERWIDTH(c) >= xmax) + { + c->x = xmax - c->width; + } + if (c->y + c->height + BARHEIGHT() >= ymax) + { + c->y = (ymax - c->height) - BARHEIGHT(); + } #ifdef DEBUG - fprintf(stderr, "fix_position(): client is (%d, %d)-(%d, %d)\n", c->x, c->y, c->x + c->width, c->y + c->height); + fprintf(stderr, "fix_position(): client is (%d, %d)-(%d, %d)\n", c->x, c->y, c->x + c->width, c->y + c->height); #endif - c->x -= BORDERWIDTH(c); - c->y -= BORDERWIDTH(c); + c->x -= BORDERWIDTH(c); + c->y -= BORDERWIDTH(c); } void refix_position(Client *c, XConfigureRequestEvent *e) { - Rect olddims; - olddims.x = c->x - BORDERWIDTH(c); - olddims.y = c->y - BORDERWIDTH(c); - olddims.width = c->width; - olddims.height = c->height; - fix_position(c); - if (olddims.x != c->x) - { - e->value_mask |= CWX; - } - if (olddims.y != c->y) - { - e->value_mask |= CWY; - } - if (olddims.width != c->width) - { - e->value_mask |= CWWidth; - } - if (olddims.height != c->height) - { - e->value_mask |= CWHeight; - } + Rect olddims; + olddims.x = c->x - BORDERWIDTH(c); + olddims.y = c->y - BORDERWIDTH(c); + olddims.width = c->width; + olddims.height = c->height; + fix_position(c); + if (olddims.x != c->x) + { + e->value_mask |= CWX; + } + if (olddims.y != c->y) + { + e->value_mask |= CWY; + } + if (olddims.width != c->width) + { + e->value_mask |= CWWidth; + } + if (olddims.height != c->height) + { + e->value_mask |= CWHeight; + } } void copy_dims(Rect *sourcedims, Rect *destdims) { - destdims->x = sourcedims->x; - destdims->y = sourcedims->y; - destdims->width = sourcedims->width; - destdims->height = sourcedims->height; + destdims->x = sourcedims->x; + destdims->y = sourcedims->y; + destdims->width = sourcedims->width; + destdims->height = sourcedims->height; } #ifdef DEBUG @@ -257,110 +257,110 @@ void copy_dims(Rect *sourcedims, Rect *destdims) /* Bleh, stupid macro names. I'm not feeling creative today. */ #define SHOW_EV(name, memb) \ - case name: \ - s = #name; \ - w = e.memb.window; \ - break; + case name: \ + s = #name; \ + w = e.memb.window; \ + break; #define SHOW(name) \ - case name: \ - return #name; + case name: \ + return #name; void show_event(XEvent e) { - char *s, buf[20]; - Window w; - Client *c; - - switch (e.type) - { - SHOW_EV(ButtonPress, xbutton) - SHOW_EV(ButtonRelease, xbutton) - SHOW_EV(ClientMessage, xclient) - SHOW_EV(ColormapNotify, xcolormap) - SHOW_EV(ConfigureNotify, xconfigure) - SHOW_EV(ConfigureRequest, xconfigurerequest) - SHOW_EV(CreateNotify, xcreatewindow) - SHOW_EV(DestroyNotify, xdestroywindow) - SHOW_EV(EnterNotify, xcrossing) - SHOW_EV(Expose, xexpose) - SHOW_EV(MapNotify, xmap) - SHOW_EV(MapRequest, xmaprequest) - SHOW_EV(MappingNotify, xmapping) - SHOW_EV(MotionNotify, xmotion) - SHOW_EV(PropertyNotify, xproperty) - SHOW_EV(ReparentNotify, xreparent) - SHOW_EV(ResizeRequest, xresizerequest) - SHOW_EV(UnmapNotify, xunmap) - default: - if (shape && e.type == shape_event) - { - s = "ShapeNotify"; - w = ((XShapeEvent *)&e)->window; - } - else - { - s = "unknown event"; - w = None; - } - break; - } - - c = find_client(w, WINDOW); - snprintf(buf, sizeof buf, c != NULL ? c->name : "(none)"); - err("%#-10lx: %-20s: %s", w, buf, s); + char *s, buf[20]; + Window w; + Client *c; + + switch (e.type) + { + SHOW_EV(ButtonPress, xbutton) + SHOW_EV(ButtonRelease, xbutton) + SHOW_EV(ClientMessage, xclient) + SHOW_EV(ColormapNotify, xcolormap) + SHOW_EV(ConfigureNotify, xconfigure) + SHOW_EV(ConfigureRequest, xconfigurerequest) + SHOW_EV(CreateNotify, xcreatewindow) + SHOW_EV(DestroyNotify, xdestroywindow) + SHOW_EV(EnterNotify, xcrossing) + SHOW_EV(Expose, xexpose) + SHOW_EV(MapNotify, xmap) + SHOW_EV(MapRequest, xmaprequest) + SHOW_EV(MappingNotify, xmapping) + SHOW_EV(MotionNotify, xmotion) + SHOW_EV(PropertyNotify, xproperty) + SHOW_EV(ReparentNotify, xreparent) + SHOW_EV(ResizeRequest, xresizerequest) + SHOW_EV(UnmapNotify, xunmap) + default: + if (shape && e.type == shape_event) + { + s = "ShapeNotify"; + w = ((XShapeEvent *)&e)->window; + } + else + { + s = "unknown event"; + w = None; + } + break; + } + + c = find_client(w, WINDOW); + snprintf(buf, sizeof buf, c != NULL ? c->name : "(none)"); + err("%#-10lx: %-20s: %s", w, buf, s); } static const char *show_state(Client *c) { - switch (get_wm_state(c)) - { - SHOW(WithdrawnState) - SHOW(NormalState) - SHOW(IconicState) - default: return "unknown state"; - } + switch (get_wm_state(c)) + { + SHOW(WithdrawnState) + SHOW(NormalState) + SHOW(IconicState) + default: return "unknown state"; + } } static const char *show_grav(Client *c) { - if (c->size == NULL || !(c->size->flags & PWinGravity)) - { - return "no grav (NW)"; - } - - switch (c->size->win_gravity) - { - SHOW(UnmapGravity) - SHOW(NorthWestGravity) - SHOW(NorthGravity) - SHOW(NorthEastGravity) - SHOW(WestGravity) - SHOW(CenterGravity) - SHOW(EastGravity) - SHOW(SouthWestGravity) - SHOW(SouthGravity) - SHOW(SouthEastGravity) - SHOW(StaticGravity) - default: return "unknown grav"; - } + if (c->size == NULL || !(c->size->flags & PWinGravity)) + { + return "no grav (NW)"; + } + + switch (c->size->win_gravity) + { + SHOW(UnmapGravity) + SHOW(NorthWestGravity) + SHOW(NorthGravity) + SHOW(NorthEastGravity) + SHOW(WestGravity) + SHOW(CenterGravity) + SHOW(EastGravity) + SHOW(SouthWestGravity) + SHOW(SouthGravity) + SHOW(SouthEastGravity) + SHOW(StaticGravity) + default: return "unknown grav"; + } } void dump(Client *c) { - if (c != NULL) - { - err("%s\n\t%s, %s, ignore %d, was_hidden %d\n\tframe %#lx, win %#lx, geom %dx%d+%d+%d", c->name, show_state(c), show_grav(c), c->ignore_unmap, c->was_hidden, c->frame, c->window, c->width, c->height, c->x, c->y); - } + if (c != NULL) + { + err("%s\n\t%s, %s, ignore %d, was_hidden %d\n\tframe %#lx, win %#lx, geom %dx%d+%d+%d", c->name, show_state(c), show_grav(c), c->ignore_unmap, c->was_hidden, c->frame, c->window, c->width, c->height, c->x, c->y); + } } void dump_clients(void) { - Client *c = head_client; - while (c != NULL) - { - dump(c); - c = c->next; - } + Client *c = head_client; + while (c != NULL) + { + dump(c); + c = c->next; + } } #endif @@ -369,40 +369,38 @@ void dump_clients(void) static void quit_nicely(void) { - unsigned int nwins, i; - Window dummyw1, dummyw2, *wins; - Client *c; - - free_menuitems(); - - XQueryTree(dsply, root, &dummyw1, &dummyw2, &wins, &nwins); - for (i = 0; i < nwins; i++) - { - c = find_client(wins[i], FRAME); - if (c != NULL) - { - remove_client(c, REMAP); - } - } - XFree(wins); - - if (font) - { - XFreeFont(dsply, font); - } -#ifdef XFT - if (xftfont) - { - XftFontClose(dsply, xftfont); - } -#endif - XFreeCursor(dsply, resize_curs); - XFreeGC(dsply, border_gc); - XFreeGC(dsply, text_gc); - - XInstallColormap(dsply, DefaultColormap(dsply, screen)); - XSetInputFocus(dsply, PointerRoot, RevertToNone, CurrentTime); - - XCloseDisplay(dsply); - exit(0); + unsigned int nwins, i; + Window dummyw1, dummyw2, *wins; + Client *c; + + free_menuitems(); + + XQueryTree(dsply, root, &dummyw1, &dummyw2, &wins, &nwins); + for (i = 0; i < nwins; i++) + { + c = find_client(wins[i], FRAME); + if (c != NULL) + { + remove_client(c, REMAP); + } + } + XFree(wins); + + if (font) + { + XFreeFont(dsply, font); + } + if (xftfont) + { + XftFontClose(dsply, xftfont); + } + XFreeCursor(dsply, resize_curs); + XFreeGC(dsply, border_gc); + XFreeGC(dsply, text_gc); + + XInstallColormap(dsply, DefaultColormap(dsply, screen)); + XSetInputFocus(dsply, PointerRoot, RevertToNone, CurrentTime); + + XCloseDisplay(dsply); + exit(0); } diff --git a/new.c b/new.c index a7268a3..03be4df 100644 --- a/new.c +++ b/new.c @@ -35,118 +35,113 @@ static PropMwmHints *get_mwm_hints(Window); void make_new_client(Window w) { - Client *c, *p; - XWindowAttributes attr; - XWMHints *hints; + Client *c, *p; + XWindowAttributes attr; + XWMHints *hints; #ifdef MWM_HINTS - PropMwmHints *mhints; + PropMwmHints *mhints; #endif - long dummy; - - c = (Client *)malloc(sizeof *c); - if (head_client == NULL) - { - head_client = c; - } - else - { - p = head_client; - while (p->next != NULL) - { - p = p->next; - } - p->next = c; - } - c->next = NULL; - - XGrabServer(dsply); - - XGetTransientForHint(dsply, w, &c->trans); - XFetchName(dsply, w, &c->name); - XGetWindowAttributes(dsply, w, &attr); - - c->window = w; - c->ignore_unmap = 0; - c->hidden = 0; - c->was_hidden = 0; -#ifdef SHAPE - c->has_been_shaped = 0; -#endif - c->x = attr.x; - c->y = attr.y; - c->width = attr.width; - c->height = attr.height; - c->cmap = attr.colormap; - c->size = XAllocSizeHints(); - XGetWMNormalHints(dsply, c->window, c->size, &dummy); + long dummy; + + c = (Client *)malloc(sizeof *c); + if (head_client == NULL) + { + head_client = c; + } + else + { + p = head_client; + while (p->next != NULL) + { + p = p->next; + } + p->next = c; + } + c->next = NULL; + + XGrabServer(dsply); + + XGetTransientForHint(dsply, w, &c->trans); + XFetchName(dsply, w, &c->name); + XGetWindowAttributes(dsply, w, &attr); + + c->window = w; + c->ignore_unmap = 0; + c->hidden = 0; + c->was_hidden = 0; + c->x = attr.x; + c->y = attr.y; + c->width = attr.width; + c->height = attr.height; + c->cmap = attr.colormap; + c->size = XAllocSizeHints(); + XGetWMNormalHints(dsply, c->window, c->size, &dummy); #ifdef MWM_HINTS - c->has_title = 1; - c->has_border = 1; - - if ((mhints = get_mwm_hints(c->window))) - { - if (mhints->flags & MWM_HINTS_DECORATIONS && !(mhints->decorations & MWM_DECOR_ALL)) - { - c->has_title = mhints->decorations & MWM_DECOR_TITLE; - c->has_border = mhints->decorations & MWM_DECOR_BORDER; - } - XFree(mhints); - } -#endif - - // XReparentWindow seems to try an XUnmapWindow, regardless of whether the reparented window is mapped or not - c->ignore_unmap++; - - if (attr.map_state != IsViewable) - { - init_position(c); - set_wm_state(c, NormalState); - if ((hints = XGetWMHints(dsply, w))) - { - if (hints->flags & StateHint) - { - set_wm_state(c, hints->initial_state); - } - XFree(hints); - } - } - - fix_position(c); - gravitate(c, APPLY_GRAVITY); - reparent(c); - -#ifdef XFT - c->xftdraw = XftDrawCreate(dsply, (Drawable) c->frame, DefaultVisual(dsply, DefaultScreen(dsply)), DefaultColormap(dsply, DefaultScreen(dsply))); + c->has_title = 1; + c->has_border = 1; + + if ((mhints = get_mwm_hints(c->window))) + { + if (mhints->flags & MWM_HINTS_DECORATIONS && !(mhints->decorations & MWM_DECOR_ALL)) + { + c->has_title = mhints->decorations & MWM_DECOR_TITLE; + c->has_border = mhints->decorations & MWM_DECOR_BORDER; + } + XFree(mhints); + } #endif - if (get_wm_state(c) != IconicState) - { - XMapWindow(dsply, c->window); - XMapRaised(dsply, c->frame); - - topmost_client = c; - } - else - { - c->hidden = 1; - if(attr.map_state == IsViewable) - { - c->ignore_unmap++; - XUnmapWindow(dsply, c->window); - } - } - - // if no client has focus give focus to the new client - if (focused_client == NULL) - { - check_focus(c); - focused_client = c; - } - - XSync(dsply, False); - XUngrabServer(dsply); - - redraw_taskbar(); + // XReparentWindow seems to try an XUnmapWindow, regardless of whether the reparented window is mapped or not + c->ignore_unmap++; + + if (attr.map_state != IsViewable) + { + init_position(c); + set_wm_state(c, NormalState); + if ((hints = XGetWMHints(dsply, w))) + { + if (hints->flags & StateHint) + { + set_wm_state(c, hints->initial_state); + } + XFree(hints); + } + } + + fix_position(c); + gravitate(c, APPLY_GRAVITY); + reparent(c); + + c->xftdraw = XftDrawCreate(dsply, (Drawable) c->frame, DefaultVisual(dsply, DefaultScreen(dsply)), DefaultColormap(dsply, DefaultScreen(dsply))); + + if (get_wm_state(c) != IconicState) + { + XMapWindow(dsply, c->window); + XMapRaised(dsply, c->frame); + + topmost_client = c; + } + else + { + c->hidden = 1; + if(attr.map_state == IsViewable) + { + c->ignore_unmap++; + XUnmapWindow(dsply, c->window); + } + } + + // if no client has focus give focus to the new client + if (focused_client == NULL) + { + check_focus(c); + focused_client = c; + } + + XSync(dsply, False); + XUngrabServer(dsply); + + redraw_taskbar(); } /* This one does *not* free the data coming back from Xlib; it just @@ -155,19 +150,19 @@ void make_new_client(Window w) #ifdef MWM_HINTS static PropMwmHints *get_mwm_hints(Window w) { - Atom real_type; - int real_format; - unsigned long items_read, items_left; - unsigned char *data; - - if (XGetWindowProperty(dsply, w, mwm_hints, 0L, 20L, False, mwm_hints, &real_type, &real_format, &items_read, &items_left, &data) == Success && items_read >= PROP_MWM_HINTS_ELEMENTS) - { - return (PropMwmHints *)data; - } - else - { - return NULL; - } + Atom real_type; + int real_format; + unsigned long items_read, items_left; + unsigned char *data; + + if (XGetWindowProperty(dsply, w, mwm_hints, 0L, 20L, False, mwm_hints, &real_type, &real_format, &items_read, &items_left, &data) == Success && items_read >= PROP_MWM_HINTS_ELEMENTS) + { + return (PropMwmHints *)data; + } + else + { + return NULL; + } } #endif @@ -188,50 +183,42 @@ static PropMwmHints *get_mwm_hints(Window w) static void init_position(Client *c) { - int mousex, mousey; - - // make sure it's big enough for the 3 buttons and a bit of bar - if (c->width < 4 * BARHEIGHT()) - { - c->width = 4 * BARHEIGHT(); - } - if (c->height < BARHEIGHT()) - { - c->height = BARHEIGHT(); - } - - if (c->x == 0 && c->y == 0) - { - get_mouse_position(&mousex, &mousey); - c->x = mousex; - c->y = mousey + BARHEIGHT(); - gravitate(c, REMOVE_GRAVITY); - } + int mousex, mousey; + + // make sure it's big enough for the 3 buttons and a bit of bar + if (c->width < 4 * BARHEIGHT()) + { + c->width = 4 * BARHEIGHT(); + } + if (c->height < BARHEIGHT()) + { + c->height = BARHEIGHT(); + } + + if (c->x == 0 && c->y == 0) + { + get_mouse_position(&mousex, &mousey); + c->x = mousex; + c->y = mousey + BARHEIGHT(); + gravitate(c, REMOVE_GRAVITY); + } } static void reparent(Client *c) { - XSetWindowAttributes pattr; - - pattr.override_redirect = True; - pattr.background_pixel = empty_col.pixel; - pattr.border_pixel = border_col.pixel; - pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; - c->frame = XCreateWindow(dsply, root, c->x, c->y - BARHEIGHT(), c->width, c->height + BARHEIGHT(), BORDERWIDTH(c), DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &pattr); - -#ifdef SHAPE - if (shape) - { - XShapeSelectInput(dsply, c->window, ShapeNotifyMask); - set_shape(c); - } -#endif + XSetWindowAttributes pattr; + + pattr.override_redirect = True; + pattr.background_pixel = empty_col.pixel; + pattr.border_pixel = border_col.pixel; + pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; + c->frame = XCreateWindow(dsply, root, c->x, c->y - BARHEIGHT(), c->width, c->height + BARHEIGHT(), BORDERWIDTH(c), DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &pattr); - XAddToSaveSet(dsply, c->window); - XSelectInput(dsply, c->window, ColormapChangeMask|PropertyChangeMask); - XSetWindowBorderWidth(dsply, c->window, 0); - XResizeWindow(dsply, c->window, c->width, c->height); - XReparentWindow(dsply, c->window, c->frame, 0, BARHEIGHT()); + XAddToSaveSet(dsply, c->window); + XSelectInput(dsply, c->window, ColormapChangeMask|PropertyChangeMask); + XSetWindowBorderWidth(dsply, c->window, 0); + XResizeWindow(dsply, c->window, c->width, c->height); + XReparentWindow(dsply, c->window, c->frame, 0, BARHEIGHT()); - send_config(c); + send_config(c); } diff --git a/taskbar.c b/taskbar.c index bfc381a..7a56530 100644 --- a/taskbar.c +++ b/taskbar.c @@ -25,417 +25,401 @@ static unsigned int update_menuitem(int); static void draw_menuitem(unsigned int, unsigned int); Window taskbar; -#ifdef XFT XftDraw *tbxftdraw; -#endif void make_taskbar(void) { - XSetWindowAttributes pattr; + XSetWindowAttributes pattr; - pattr.override_redirect = True; - pattr.background_pixel = empty_col.pixel; - pattr.border_pixel = border_col.pixel; - pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; - taskbar = XCreateWindow(dsply, root, 0 - DEF_BORDERWIDTH, 0 - DEF_BORDERWIDTH, DisplayWidth(dsply, screen), BARHEIGHT() - DEF_BORDERWIDTH, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &pattr); + pattr.override_redirect = True; + pattr.background_pixel = empty_col.pixel; + pattr.border_pixel = border_col.pixel; + pattr.event_mask = ChildMask|ButtonPressMask|ExposureMask|EnterWindowMask; + taskbar = XCreateWindow(dsply, root, 0 - DEF_BORDERWIDTH, 0 - DEF_BORDERWIDTH, DisplayWidth(dsply, screen), BARHEIGHT() - DEF_BORDERWIDTH, DEF_BORDERWIDTH, DefaultDepth(dsply, screen), CopyFromParent, DefaultVisual(dsply, screen), CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWEventMask, &pattr); - XMapWindow(dsply, taskbar); + XMapWindow(dsply, taskbar); -#ifdef XFT - tbxftdraw = XftDrawCreate(dsply, (Drawable) taskbar, DefaultVisual(dsply, DefaultScreen(dsply)), DefaultColormap(dsply, DefaultScreen(dsply))); -#endif + tbxftdraw = XftDrawCreate(dsply, (Drawable) taskbar, DefaultVisual(dsply, DefaultScreen(dsply)), DefaultColormap(dsply, DefaultScreen(dsply))); } void remember_hidden(void) { - Client *c; - for (c = head_client; c != NULL; c = c->next) - { - c->was_hidden = c->hidden; - } + Client *c; + for (c = head_client; c != NULL; c = c->next) + { + c->was_hidden = c->hidden; + } } void forget_hidden(void) { - Client *c; - for (c = head_client; c != NULL; c = c->next) - { - if (c == focused_client) - { - c->was_hidden = c->hidden; - } - else - { - c->was_hidden = 0; - } - } + Client *c; + for (c = head_client; c != NULL; c = c->next) + { + if (c == focused_client) + { + c->was_hidden = c->hidden; + } + else + { + c->was_hidden = 0; + } + } } void lclick_taskbutton(Client *old_c, Client *c) { - if (old_c != NULL) - { - if (old_c->was_hidden) - { - hide(old_c); - } - } - - if (c->hidden) - { - unhide(c); - } - else - { - if (c->was_hidden) - { - hide(c); - } - else - { - raise_lower(c); - } - } - check_focus(c); + if (old_c != NULL) + { + if (old_c->was_hidden) + { + hide(old_c); + } + } + + if (c->hidden) + { + unhide(c); + } + else + { + if (c->was_hidden) + { + hide(c); + } + else + { + raise_lower(c); + } + } + check_focus(c); } void lclick_taskbar(int x) { - XEvent ev; - int mousex, mousey; - Rect bounddims; - Window constraint_win; - XSetWindowAttributes pattr; - - float button_width; - unsigned int button_clicked, old_button_clicked, i; - Client *c, *exposed_c, *old_c; - if (head_client != NULL) - { - remember_hidden(); - - get_mouse_position(&mousex, &mousey); - - bounddims.x = 0; - bounddims.y = 0; - bounddims.width = DisplayWidth(dsply, screen); - bounddims.height = BARHEIGHT(); - - constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); - XMapWindow(dsply, constraint_win); - - if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) - { - XDestroyWindow(dsply, constraint_win); - return; - } - - button_width = get_button_width(); - - button_clicked = (unsigned int)(x / button_width); - for (i = 0, c = head_client; i < button_clicked; i++) - { - c = c->next; - } - - lclick_taskbutton(NULL, c); - - do - { - XMaskEvent(dsply, ExposureMask|MouseMask|KeyMask, &ev); - switch (ev.type) - { - case Expose: - exposed_c = find_client(ev.xexpose.window, FRAME); - if (exposed_c) - { - redraw(exposed_c); - } - break; - case MotionNotify: - old_button_clicked = button_clicked; - button_clicked = (unsigned int)(ev.xmotion.x / button_width); - if (button_clicked != old_button_clicked) - { - old_c = c; - for (i = 0, c = head_client; i < button_clicked; i++) - { - c = c->next; - } - lclick_taskbutton(old_c, c); - } - break; - case KeyPress: - XPutBackEvent(dsply, &ev); - break; - } - } - while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress); - - XUnmapWindow(dsply, constraint_win); - XDestroyWindow(dsply, constraint_win); - ungrab(); - - forget_hidden(); - } + XEvent ev; + int mousex, mousey; + Rect bounddims; + Window constraint_win; + XSetWindowAttributes pattr; + + float button_width; + unsigned int button_clicked, old_button_clicked, i; + Client *c, *exposed_c, *old_c; + if (head_client != NULL) + { + remember_hidden(); + + get_mouse_position(&mousex, &mousey); + + bounddims.x = 0; + bounddims.y = 0; + bounddims.width = DisplayWidth(dsply, screen); + bounddims.height = BARHEIGHT(); + + constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); + XMapWindow(dsply, constraint_win); + + if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) + { + XDestroyWindow(dsply, constraint_win); + return; + } + + button_width = get_button_width(); + + button_clicked = (unsigned int)(x / button_width); + for (i = 0, c = head_client; i < button_clicked; i++) + { + c = c->next; + } + + lclick_taskbutton(NULL, c); + + do + { + XMaskEvent(dsply, ExposureMask|MouseMask|KeyMask, &ev); + switch (ev.type) + { + case Expose: + exposed_c = find_client(ev.xexpose.window, FRAME); + if (exposed_c) + { + redraw(exposed_c); + } + break; + case MotionNotify: + old_button_clicked = button_clicked; + button_clicked = (unsigned int)(ev.xmotion.x / button_width); + if (button_clicked != old_button_clicked) + { + old_c = c; + for (i = 0, c = head_client; i < button_clicked; i++) + { + c = c->next; + } + lclick_taskbutton(old_c, c); + } + break; + case KeyPress: + XPutBackEvent(dsply, &ev); + break; + } + } + while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress); + + XUnmapWindow(dsply, constraint_win); + XDestroyWindow(dsply, constraint_win); + ungrab(); + + forget_hidden(); + } } void rclick_taskbar(int x) { - XEvent ev; - int mousex, mousey; - Rect bounddims; - unsigned int current_item = UINT_MAX; - Window constraint_win; - XSetWindowAttributes pattr; - - get_mouse_position(&mousex, &mousey); - - bounddims.x = 0; - bounddims.y = 0; - bounddims.width = DisplayWidth(dsply, screen); - bounddims.height = BARHEIGHT(); - - constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); - XMapWindow(dsply, constraint_win); - - if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) - { - XDestroyWindow(dsply, constraint_win); - return; - } - draw_menubar(); - update_menuitem(INT_MAX); // force initial highlight - current_item = update_menuitem(x); - do - { - XMaskEvent(dsply, MouseMask|KeyMask, &ev); - switch (ev.type) - { - case MotionNotify: - current_item = update_menuitem(ev.xmotion.x); - break; - case ButtonRelease: - if (current_item != UINT_MAX) - { - fork_exec(menuitems[current_item].command); - } - break; - case KeyPress: - XPutBackEvent(dsply, &ev); - break; - } - } - while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress); - - redraw_taskbar(); - XUnmapWindow(dsply, constraint_win); - XDestroyWindow(dsply, constraint_win); - ungrab(); + XEvent ev; + int mousex, mousey; + Rect bounddims; + unsigned int current_item = UINT_MAX; + Window constraint_win; + XSetWindowAttributes pattr; + + get_mouse_position(&mousex, &mousey); + + bounddims.x = 0; + bounddims.y = 0; + bounddims.width = DisplayWidth(dsply, screen); + bounddims.height = BARHEIGHT(); + + constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr); + XMapWindow(dsply, constraint_win); + + if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess)) + { + XDestroyWindow(dsply, constraint_win); + return; + } + draw_menubar(); + update_menuitem(INT_MAX); // force initial highlight + current_item = update_menuitem(x); + do + { + XMaskEvent(dsply, MouseMask|KeyMask, &ev); + switch (ev.type) + { + case MotionNotify: + current_item = update_menuitem(ev.xmotion.x); + break; + case ButtonRelease: + if (current_item != UINT_MAX) + { + fork_exec(menuitems[current_item].command); + } + break; + case KeyPress: + XPutBackEvent(dsply, &ev); + break; + } + } + while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress); + + redraw_taskbar(); + XUnmapWindow(dsply, constraint_win); + XDestroyWindow(dsply, constraint_win); + ungrab(); } void rclick_root(void) { - XEvent ev; - if (!grab(root, MouseMask, None)) - { - return; - } - draw_menubar(); - do - { - XMaskEvent(dsply, MouseMask|KeyMask, &ev); - switch (ev.type) - { - case MotionNotify: - if (ev.xmotion.y < BARHEIGHT()) - { - ungrab(); - rclick_taskbar(ev.xmotion.x); - return; - } - break; - case KeyPress: - XPutBackEvent(dsply, &ev); - break; - } - } - while (ev.type != ButtonRelease && ev.type != KeyPress); - - redraw_taskbar(); - ungrab(); + XEvent ev; + if (!grab(root, MouseMask, None)) + { + return; + } + draw_menubar(); + do + { + XMaskEvent(dsply, MouseMask|KeyMask, &ev); + switch (ev.type) + { + case MotionNotify: + if (ev.xmotion.y < BARHEIGHT()) + { + ungrab(); + rclick_taskbar(ev.xmotion.x); + return; + } + break; + case KeyPress: + XPutBackEvent(dsply, &ev); + break; + } + } + while (ev.type != ButtonRelease && ev.type != KeyPress); + + redraw_taskbar(); + ungrab(); } void redraw_taskbar(void) { - unsigned int i; - int button_startx, button_iwidth; - float button_width; - Client *c; - - button_width = get_button_width(); - XClearWindow(dsply, taskbar); - - if (showing_taskbar == 0) - { - return; - } - - for (c = head_client, i = 0; c != NULL; c = c->next, i++) - { - button_startx = (int)(i * button_width); - button_iwidth = (unsigned int)(((i + 1) * button_width) - button_startx); - if (button_startx != 0) - { - XDrawLine(dsply, taskbar, border_gc, button_startx - 1, 0, button_startx - 1, BARHEIGHT() - DEF_BORDERWIDTH); - } - if (c == focused_client) - { - XFillRectangle(dsply, taskbar, active_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH); - } - else - { - XFillRectangle(dsply, taskbar, inactive_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH); - } - if (!c->trans && c->name != NULL) - { -#ifdef XFT - XftDrawString8(tbxftdraw, &xft_detail, xftfont, button_startx + SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name)); -#else - XDrawString(dsply, taskbar, text_gc, button_startx + SPACE, SPACE + font->ascent, c->name, strlen(c->name)); -#endif - } - } + unsigned int i; + int button_startx, button_iwidth; + float button_width; + Client *c; + + button_width = get_button_width(); + XClearWindow(dsply, taskbar); + + if (showing_taskbar == 0) + { + return; + } + + for (c = head_client, i = 0; c != NULL; c = c->next, i++) + { + button_startx = (int)(i * button_width); + button_iwidth = (unsigned int)(((i + 1) * button_width) - button_startx); + if (button_startx != 0) + { + XDrawLine(dsply, taskbar, border_gc, button_startx - 1, 0, button_startx - 1, BARHEIGHT() - DEF_BORDERWIDTH); + } + if (c == focused_client) + { + XFillRectangle(dsply, taskbar, active_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH); + } + else + { + XFillRectangle(dsply, taskbar, inactive_gc, button_startx, 0, button_iwidth, BARHEIGHT() - DEF_BORDERWIDTH); + } + if (!c->trans && c->name != NULL) + { + XftDrawString8(tbxftdraw, &xft_detail, xftfont, button_startx + SPACE, SPACE + xftfont->ascent, (unsigned char *)c->name, strlen(c->name)); + } + } } void draw_menubar(void) { - unsigned int i, dw; - dw = DisplayWidth(dsply, screen); - XFillRectangle(dsply, taskbar, menu_gc, 0, 0, dw, BARHEIGHT() - DEF_BORDERWIDTH); - - for (i = 0; i < num_menuitems; i++) - { - if (menuitems[i].label && menuitems[i].command) - { -#ifdef XFT - XftDrawString8(tbxftdraw, &xft_detail, xftfont, menuitems[i].x + (SPACE * 2), xftfont->ascent + SPACE, (unsigned char *)menuitems[i].label, strlen(menuitems[i].label)); -#else - XDrawString(dsply, taskbar, text_gc, menuitems[i].x + (SPACE * 2), font->ascent + SPACE, menuitems[i].label, strlen(menuitems[i].label)); -#endif - } - } + unsigned int i, dw; + dw = DisplayWidth(dsply, screen); + XFillRectangle(dsply, taskbar, menu_gc, 0, 0, dw, BARHEIGHT() - DEF_BORDERWIDTH); + + for (i = 0; i < num_menuitems; i++) + { + if (menuitems[i].label && menuitems[i].command) + { + XftDrawString8(tbxftdraw, &xft_detail, xftfont, menuitems[i].x + (SPACE * 2), xftfont->ascent + SPACE, (unsigned char *)menuitems[i].label, strlen(menuitems[i].label)); + } + } } unsigned int update_menuitem(int mousex) { - static unsigned int last_item; // retain value from last call - unsigned int i; - if (mousex == INT_MAX) // entered function to set last_item - { - last_item = num_menuitems; - return UINT_MAX; - } - for (i = 0; i < num_menuitems; i++) - { - if ((mousex >= menuitems[i].x) && (mousex <= (menuitems[i].x + menuitems[i].width))) - { - break; - } - } - - if (i != last_item) // don't redraw if same - { - if (last_item != num_menuitems) - { - draw_menuitem(last_item, 0); - } - if (i != num_menuitems) - { - draw_menuitem(i, 1); - } - last_item = i; // set to new menu item - } - - if (i != num_menuitems) - { - return i; - } - else // no item selected - { - return UINT_MAX; - } + static unsigned int last_item; // retain value from last call + unsigned int i; + if (mousex == INT_MAX) // entered function to set last_item + { + last_item = num_menuitems; + return UINT_MAX; + } + for (i = 0; i < num_menuitems; i++) + { + if ((mousex >= menuitems[i].x) && (mousex <= (menuitems[i].x + menuitems[i].width))) + { + break; + } + } + + if (i != last_item) // don't redraw if same + { + if (last_item != num_menuitems) + { + draw_menuitem(last_item, 0); + } + if (i != num_menuitems) + { + draw_menuitem(i, 1); + } + last_item = i; // set to new menu item + } + + if (i != num_menuitems) + { + return i; + } + else // no item selected + { + return UINT_MAX; + } } void draw_menuitem(unsigned int index, unsigned int active) { - if (active) - { - XFillRectangle(dsply, taskbar, selected_gc, menuitems[index].x, 0, menuitems[index].width, BARHEIGHT() - DEF_BORDERWIDTH); - } - else - { - XFillRectangle(dsply, taskbar, menu_gc, menuitems[index].x, 0, menuitems[index].width, BARHEIGHT() - DEF_BORDERWIDTH); - } -#ifdef XFT - XftDrawString8(tbxftdraw, &xft_detail, xftfont, menuitems[index].x + (SPACE * 2), xftfont->ascent + SPACE, (unsigned char *)menuitems[index].label, strlen(menuitems[index].label)); -#else - XDrawString(dsply, taskbar, text_gc, menuitems[index].x + (SPACE * 2), font->ascent + SPACE, menuitems[index].label, strlen(menuitems[index].label)); -#endif + if (active) + { + XFillRectangle(dsply, taskbar, selected_gc, menuitems[index].x, 0, menuitems[index].width, BARHEIGHT() - DEF_BORDERWIDTH); + } + else + { + XFillRectangle(dsply, taskbar, menu_gc, menuitems[index].x, 0, menuitems[index].width, BARHEIGHT() - DEF_BORDERWIDTH); + } + XftDrawString8(tbxftdraw, &xft_detail, xftfont, menuitems[index].x + (SPACE * 2), xftfont->ascent + SPACE, (unsigned char *)menuitems[index].label, strlen(menuitems[index].label)); } float get_button_width(void) { - unsigned int nwins = 0; - Client *c = head_client; - while (c != NULL) - { - nwins++; - c = c->next; - } - return ((float)(DisplayWidth(dsply, screen) + DEF_BORDERWIDTH)) / nwins; + unsigned int nwins = 0; + Client *c = head_client; + while (c != NULL) + { + nwins++; + c = c->next; + } + return ((float)(DisplayWidth(dsply, screen) + DEF_BORDERWIDTH)) / nwins; } void cycle_previous(void) { - Client *c = focused_client; - Client *original_c = c; - if (head_client != NULL && head_client->next != NULL) // at least 2 windows exist - { - if (c == NULL) - { - c = head_client; - } - if (c == head_client) - { - original_c = NULL; - } - do - { - if (c->next == NULL) - { - c = head_client; - } - else - { - c = c->next; - } - } - while (c->next != original_c); - lclick_taskbutton(NULL, c); - } + Client *c = focused_client; + Client *original_c = c; + if (head_client != NULL && head_client->next != NULL) // at least 2 windows exist + { + if (c == NULL) + { + c = head_client; + } + if (c == head_client) + { + original_c = NULL; + } + do + { + if (c->next == NULL) + { + c = head_client; + } + else + { + c = c->next; + } + } + while (c->next != original_c); + lclick_taskbutton(NULL, c); + } } void cycle_next(void) { - Client *c = focused_client; - if (head_client != NULL && head_client->next != NULL) // at least 2 windows exist - { - if (c == NULL || c->next == NULL) - { - c = head_client; - } - else c = c->next; - lclick_taskbutton(NULL, c); - } + Client *c = focused_client; + if (head_client != NULL && head_client->next != NULL) // at least 2 windows exist + { + if (c == NULL || c->next == NULL) + { + c = head_client; + } + else c = c->next; + lclick_taskbutton(NULL, c); + } } diff --git a/windowlab.h b/windowlab.h index 8a1d3a1..f641231 100644 --- a/windowlab.h +++ b/windowlab.h @@ -36,12 +36,7 @@ #include #include #include -#ifdef SHAPE -#include -#endif -#ifdef XFT #include -#endif #ifdef MWM_HINTS // These definitions are taken from LessTif 0.95.0's MwmUtil.h. @@ -61,15 +56,15 @@ #define _XA_MWM_HINTS "_MOTIF_WM_HINTS" -#define PROP_MWM_HINTS_ELEMENTS 5 +#define PROP_MWM_HINTS_ELEMENTS 5 typedef struct PropMwmHints { - CARD32 flags; - CARD32 functions; - CARD32 decorations; - INT32 inputMode; - CARD32 status; + CARD32 flags; + CARD32 functions; + CARD32 decorations; + INT32 inputMode; + CARD32 status; } PropMwmHints; #endif @@ -80,11 +75,7 @@ typedef struct PropMwmHints // here are the default settings - change to suit your taste // if you aren't sure about DEF_FONT, change it to "fixed"; almost all X installations will have that available -#ifdef XFT #define DEF_FONT "-bitstream-bitstream vera sans-medium-r-*-*-*-100-*-*-*-*-*-*" -#else -#define DEF_FONT "-b&h-lucida-medium-r-*-*-10-*-*-*-*-*-*-*" -#endif // use named colours, #rgb, #rrggbb or #rrrgggbbb format #define DEF_BORDER "#000" @@ -100,7 +91,7 @@ typedef struct PropMwmHints // change MODIFIER to None to remove the need to hold down a modifier key // the Windows key should be Mod4Mask and the Alt key is Mod1Mask -#define MODIFIER Mod1Mask +#define MODIFIER Mod4Mask // keys may be used by other apps, so change them here #define KEY_CYCLEPREV XK_Tab @@ -123,15 +114,15 @@ typedef struct PropMwmHints #define setmouse(w, x, y) XWarpPointer(dsply, None, w, 0, 0, 0, 0, x, y) #define ungrab() XUngrabPointer(dsply, CurrentTime) #define grab(w, mask, curs) \ - (XGrabPointer(dsply, w, False, mask, GrabModeAsync, GrabModeAsync, None, curs, CurrentTime) == GrabSuccess) + (XGrabPointer(dsply, w, False, mask, GrabModeAsync, GrabModeAsync, None, curs, CurrentTime) == GrabSuccess) #define grab_keysym(w, mask, keysym) \ - XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), mask, w, True, GrabModeAsync, GrabModeAsync); \ - XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), LockMask|mask, w, True, GrabModeAsync, GrabModeAsync); \ - if (numlockmask) \ - { \ - XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), numlockmask|mask, w, True, GrabModeAsync, GrabModeAsync); \ - XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), numlockmask|LockMask|mask, w, True, GrabModeAsync, GrabModeAsync); \ - } + XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), mask, w, True, GrabModeAsync, GrabModeAsync); \ + XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), LockMask|mask, w, True, GrabModeAsync, GrabModeAsync); \ + if (numlockmask) \ + { \ + XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), numlockmask|mask, w, True, GrabModeAsync, GrabModeAsync); \ + XGrabKey(dsply, XKeysymToKeycode(dsply, keysym), numlockmask|LockMask|mask, w, True, GrabModeAsync, GrabModeAsync); \ + } // I wanna know who the morons who prototyped these functions as implicit int are... #define lower_win(c) ((void) XLowerWindow(dsply, (c)->frame)) @@ -145,11 +136,7 @@ typedef struct PropMwmHints #endif // bar height -#ifdef XFT #define BARHEIGHT() (xftfont->ascent + xftfont->descent + 2*SPACE + 2) -#else -#define BARHEIGHT() (font->ascent + font->descent + 2*SPACE + 2) -#endif // minimum window width and height, enough for 3 buttons and a bit of titlebar #define MINWINWIDTH (BARHEIGHT() * 4) @@ -181,7 +168,7 @@ typedef struct PropMwmHints /* This structure keeps track of top-level windows (hereinafter * 'clients'). The clients we know about (i.e. all that don't set * override-redirect) are kept track of in linked list starting at the - * global pointer called, appropriately, 'clients'. + * global pointer called, appropriately, 'clients'. * * window and parent refer to the actual client window and the larger * frame into which we will reparent it respectively. trans is set to @@ -196,39 +183,34 @@ typedef struct PropMwmHints typedef struct Client { - struct Client *next; - char *name; - XSizeHints *size; - Window window, frame, trans; - Colormap cmap; - int x, y; - int width, height; - int ignore_unmap; - unsigned int hidden; - unsigned int was_hidden; - unsigned int focus_order; -#ifdef SHAPE - Bool has_been_shaped; -#endif + struct Client *next; + char *name; + XSizeHints *size; + Window window, frame, trans; + Colormap cmap; + int x, y; + int width, height; + int ignore_unmap; + unsigned int hidden; + unsigned int was_hidden; + unsigned int focus_order; #ifdef MWM_HINTS - Bool has_title, has_border; -#endif -#ifdef XFT - XftDraw *xftdraw; + Bool has_title, has_border; #endif + XftDraw *xftdraw; } Client; typedef struct Rect { - int x, y; - int width, height; + int x, y; + int width, height; } Rect; typedef struct MenuItem { - char *command, *label; - int x; - int width; + char *command, *label; + int x; + int width; } MenuItem; // Below here are (mainly generated with cproto) declarations and prototypes for each file. @@ -241,10 +223,8 @@ extern Client *head_client, *focused_client, *topmost_client, *fullscreen_client extern unsigned int in_taskbar, showing_taskbar, focus_count; extern Rect fs_prevdims; extern XFontStruct *font; -#ifdef XFT extern XftFont *xftfont; extern XftColor xft_detail; -#endif extern GC border_gc, text_gc, active_gc, depressed_gc, inactive_gc, menu_gc, selected_gc, empty_gc; extern XColor border_col, text_col, active_col, depressed_col, inactive_col, menu_col, selected_col, empty_col; extern Cursor resize_curs; @@ -253,9 +233,6 @@ extern Atom wm_state, wm_change_state, wm_protos, wm_delete, wm_cmapwins; extern Atom mwm_hints; #endif extern char *opt_font, *opt_border, *opt_text, *opt_active, *opt_inactive, *opt_menu, *opt_selected, *opt_empty; -#ifdef SHAPE -extern int shape, shape_event; -#endif extern unsigned int numlockmask; // events.c @@ -269,9 +246,6 @@ extern void send_config(Client *); extern void remove_client(Client *, int); extern void redraw(Client *); extern void gravitate(Client *, int); -#ifdef SHAPE -extern void set_shape(Client *); -#endif extern void check_focus(Client *); extern Client *get_prev_focused(void); extern void draw_hide_button(Client *, GC *, GC *); @@ -310,9 +284,7 @@ extern void dump_clients(void); // taskbar.c extern Window taskbar; -#ifdef XFT extern XftDraw *tbxftdraw; -#endif extern void make_taskbar(void); extern void cycle_previous(void); extern void cycle_next(void); -- 2.54.0