From c8abcf33fbf59b5b697f1a35452300669d0a077b Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 13 Sep 2007 15:57:35 +0200 Subject: [PATCH] add XShape support --- awesome.c | 14 ++++++++++---- client.c | 17 +++++++++++++++++ client.h | 1 + config.h | 2 ++ config.mk | 2 +- event.c | 12 ++++++++++++ event.h | 1 + 7 files changed, 44 insertions(+), 5 deletions(-) diff --git a/awesome.c b/awesome.c index d035e700..2337e328 100644 --- a/awesome.c +++ b/awesome.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "awesome.h" #include "event.h" @@ -270,12 +271,13 @@ int main(int argc, char *argv[]) { char *p; - int r, xfd; + int r, xfd, e_dummy; fd_set rd; XEvent ev; Display * dpy; Window root; awesome_config awesomeconf; + int shape_event; if(argc == 2 && !strcmp("-v", argv[1])) eprint("awesome-" VERSION " © 2007 Julien Danjou\n"); @@ -301,8 +303,6 @@ main(int argc, char *argv[]) parse_config(dpy, DefaultScreen(dpy), &dc, &awesomeconf); setup(dpy, &dc, &awesomeconf); drawstatus(dpy, &dc, &awesomeconf); - scan(dpy, &dc, &awesomeconf); - XSync(dpy, False); void (*handler[LASTEvent]) (XEvent *, awesome_config *) = { @@ -317,9 +317,15 @@ main(int argc, char *argv[]) [MappingNotify] = handle_event_mappingnotify, [MapRequest] = handle_event_maprequest, [PropertyNotify] = handle_event_propertynotify, - [UnmapNotify] = handle_event_unmapnotify + [UnmapNotify] = handle_event_unmapnotify, }; + /* check for shape extension */ + if((awesomeconf.have_shape = XShapeQueryExtension(dpy, &shape_event, &e_dummy))) + handler[shape_event] = handle_event_shape; + + scan(dpy, &dc, &awesomeconf); + XSync(dpy, False); /* main event loop, also reads status text from stdin */ while(running) diff --git a/client.c b/client.c index 00c70ac9..24a6ad77 100644 --- a/client.c +++ b/client.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "awesome.h" #include "layout.h" @@ -391,6 +392,11 @@ manage(Display * disp, DC *drawcontext, Window w, XWindowAttributes * wa, awesom configure(c); /* propagates border_width, if size doesn't change */ updatesizehints(c); XSelectInput(disp, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); + if(awesomeconf->have_shape) + { + XShapeSelectInput(disp, w, ShapeNotifyMask); + set_shape(c); + } grabbuttons(c, False, awesomeconf->modkey, awesomeconf->numlockmask); updatetitle(c); if((rettrans = XGetTransientForHint(disp, w, &trans) == Success)) @@ -637,6 +643,17 @@ updatesizehints(Client * c) && c->maxw == c->minw && c->maxh == c->minh); } +void +set_shape(Client *c) +{ + int bounding_shaped; + int i, b; unsigned int u; /* dummies */ + /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */ + if (XShapeQueryExtents(c->display, c->win, &bounding_shaped, &i, &i, + &u, &u, &b, &i, &i, &u, &u) && bounding_shaped) + XShapeCombineShape(c->display, DefaultRootWindow(c->display), ShapeBounding, 0, 0, c->win, ShapeBounding, ShapeSet); +} + void uicb_settrans(Display *disp __attribute__ ((unused)), DC *drawcontext __attribute__ ((unused)), diff --git a/client.h b/client.h index 1aea89c6..9a3fb795 100644 --- a/client.h +++ b/client.h @@ -60,6 +60,7 @@ void unmanage(Client *, DC *, long, awesome_config *); /* unmanage c */ void updatesizehints(Client *); /* update the size hint variables of c */ void updatetitle(Client *); /* update the name of c */ void saveprops(Client * c, int); /* saves client properties */ +void set_shape(Client *); void uicb_killclient(Display *, DC *, awesome_config *, const char *); /* kill client */ void uicb_moveresize(Display *, DC *, awesome_config *, const char *); /* move and resize window */ void uicb_settrans(Display *, DC *, awesome_config *, const char *); diff --git a/config.h b/config.h index 4d2f7f01..a21f4bb1 100644 --- a/config.h +++ b/config.h @@ -139,6 +139,8 @@ struct awesome_config Layout * current_layout; /** Status bar */ Statusbar statusbar; + /** Check for XShape extension */ + Bool have_shape; }; void parse_config(Display *, int, DC *, awesome_config *); /* parse configuration file */ diff --git a/config.mk b/config.mk index 9011109e..7e9d7a85 100644 --- a/config.mk +++ b/config.mk @@ -15,7 +15,7 @@ X11LIB = /usr/lib/X11 # includes and libs INCS = -I. -I/usr/include -I${X11INC} `pkg-config --cflags libconfig` -LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs libconfig` +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs libconfig` -lXext # flags CFLAGS = -fgnu89-inline -std=gnu99 -ggdb3 -pipe -Wall -Wextra -W -Wchar-subscripts -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wsign-compare -Wunused -Wuninitialized -Winit-self -Wpointer-arith -Wredundant-decls -Wno-format-zero-length -Wmissing-prototypes -Wmissing-format-attribute -Wmissing-noreturn -O2 ${INCS} -DVERSION=\"${VERSION}\" diff --git a/event.c b/event.c index 8ab25032..26679077 100644 --- a/event.c +++ b/event.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "awesome.h" #include "event.h" @@ -389,6 +390,17 @@ handle_event_unmapnotify(XEvent * e, awesome_config *awesomeconf) unmanage(c, &dc, WithdrawnState, awesomeconf); } +void +handle_event_shape(XEvent * e, + awesome_config *awesomeconf __attribute__ ((unused))) +{ + XShapeEvent *ev = (XShapeEvent *) e; + Client *c = getclient(ev->window); + + if(c) + set_shape(c); +} + void grabkeys(Display *disp, awesome_config *awesomeconf) { diff --git a/event.h b/event.h index f9ecb276..fe906462 100644 --- a/event.h +++ b/event.h @@ -38,5 +38,6 @@ void handle_event_mappingnotify(XEvent *, awesome_config *); void handle_event_maprequest(XEvent *, awesome_config *); void handle_event_propertynotify(XEvent *, awesome_config *); void handle_event_unmapnotify(XEvent *, awesome_config *); +void handle_event_shape(XEvent *, awesome_config *); #endif