diff --git a/event.c b/event.c index 9e1453f97..9a56aed73 100644 --- a/event.c +++ b/event.c @@ -72,7 +72,7 @@ handle_event_buttonpress(XEvent *e) for(screen = 0; screen < globalconf.nscreens; screen++) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) - if(statusbar->window == ev->window || statusbar->window == ev->subwindow) + if(statusbar->sw->window == ev->window || statusbar->sw->window == ev->subwindow) switch(statusbar->position) { case Top: @@ -204,7 +204,7 @@ handle_event_configurenotify(XEvent * e) globalconf.screens[screen].statusbar->width = area.width; XResizeWindow(e->xany.display, - globalconf.screens[screen].statusbar->window, + globalconf.screens[screen].statusbar->sw->window, globalconf.screens[screen].statusbar->width, globalconf.screens[screen].statusbar->height); @@ -261,7 +261,7 @@ handle_event_expose(XEvent *e) if(!ev->count) for(screen = 0; screen < globalconf.nscreens; screen++) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) - if(statusbar->window == ev->window) + if(statusbar->sw->window == ev->window) { statusbar_display(statusbar); return; diff --git a/statusbar.c b/statusbar.c index 71dd6d0cf..99653027a 100644 --- a/statusbar.c +++ b/statusbar.c @@ -26,6 +26,7 @@ #include "screen.h" #include "tag.h" #include "widget.h" +#include "window.h" #include "common/util.h" extern AwesomeConf globalconf; @@ -35,7 +36,7 @@ statusbar_update_position(Statusbar *statusbar) { Area area; - XMapRaised(globalconf.display, statusbar->window); + XMapRaised(globalconf.display, statusbar->sw->window); /* Top and Bottom Statusbar have prio */ if(statusbar->position == Top || statusbar->position == Bottom) @@ -50,23 +51,23 @@ statusbar_update_position(Statusbar *statusbar) switch(statusbar->position) { case Top: - XMoveWindow(globalconf.display, statusbar->window, + XMoveWindow(globalconf.display, statusbar->sw->window, area.x, area.y); break; case Bottom: - XMoveWindow(globalconf.display, statusbar->window, + XMoveWindow(globalconf.display, statusbar->sw->window, area.x, area.height - statusbar->height); break; case Left: - XMoveWindow(globalconf.display, statusbar->window, + XMoveWindow(globalconf.display, statusbar->sw->window, area.x - statusbar->height, (area.y + area.height) - statusbar->width); break; case Right: - XMoveWindow(globalconf.display, statusbar->window, + XMoveWindow(globalconf.display, statusbar->sw->window, area.x + area.width, area.y); break; case Off: - XUnmapWindow(globalconf.display, statusbar->window); + XUnmapWindow(globalconf.display, statusbar->sw->window); break; } } @@ -83,7 +84,7 @@ statusbar_draw(Statusbar *statusbar) if(statusbar->position == Off) return; - XFreePixmap(globalconf.display, statusbar->drawable); + XFreePixmap(globalconf.display, statusbar->sw->drawable); DrawCtx *ctx = draw_get_context(phys_screen, statusbar->width, @@ -122,15 +123,15 @@ statusbar_draw(Statusbar *statusbar) || statusbar->position == Left) { if(statusbar->position == Right) - statusbar->drawable = draw_rotate(ctx, phys_screen, M_PI_2, statusbar->height, 0); + statusbar->sw->drawable = draw_rotate(ctx, phys_screen, M_PI_2, statusbar->height, 0); else - statusbar->drawable = draw_rotate(ctx, phys_screen, - M_PI_2, 0, statusbar->width); + statusbar->sw->drawable = draw_rotate(ctx, phys_screen, - M_PI_2, 0, statusbar->width); draw_free_context(ctx); } else { - statusbar->drawable = ctx->drawable; + statusbar->sw->drawable = ctx->drawable; /* just delete the struct, don't delete the drawable */ p_delete(&ctx); } @@ -149,14 +150,14 @@ statusbar_display(Statusbar *statusbar) if(statusbar->position == Right || statusbar->position == Left) - XCopyArea(globalconf.display, statusbar->drawable, - statusbar->window, + XCopyArea(globalconf.display, statusbar->sw->drawable, + statusbar->sw->window, DefaultGC(globalconf.display, phys_screen), 0, 0, statusbar->height, statusbar->width, 0, 0); else - XCopyArea(globalconf.display, statusbar->drawable, - statusbar->window, + XCopyArea(globalconf.display, statusbar->sw->drawable, + statusbar->sw->window, DefaultGC(globalconf.display, phys_screen), 0, 0, statusbar->width, statusbar->height, 0, 0); } @@ -181,7 +182,6 @@ void statusbar_init(Statusbar *statusbar) { Statusbar *sb; - XSetWindowAttributes wa; int phys_screen = get_phys_screen(statusbar->screen); Area area = get_screen_area(statusbar->screen, globalconf.screens[statusbar->screen].statusbar, @@ -208,61 +208,16 @@ statusbar_init(Statusbar *statusbar) statusbar->width = area.width; } - wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask - | EnterWindowMask | LeaveWindowMask | StructureNotifyMask; - wa.cursor = globalconf.cursor[CurNormal]; - wa.override_redirect = 1; - wa.background_pixmap = ParentRelative; - wa.event_mask = ButtonPressMask | ExposureMask; if(statusbar->dposition == Right || statusbar->dposition == Left) - statusbar->window = XCreateWindow(globalconf.display, - RootWindow(globalconf.display, - phys_screen), - 0, 0, - statusbar->height, - statusbar->width, - 0, - DefaultDepth(globalconf.display, - phys_screen), - CopyFromParent, - DefaultVisual(globalconf.display, - phys_screen), - CWOverrideRedirect | - CWBackPixmap | - CWEventMask, - &wa); + statusbar->sw = + simplewindow_new(phys_screen, 0, 0, statusbar->height, statusbar->width, 0); else - statusbar->window = XCreateWindow(globalconf.display, - RootWindow(globalconf.display, - phys_screen), - 0, 0, - statusbar->width, - statusbar->height, - 0, - DefaultDepth(globalconf.display, - phys_screen), - CopyFromParent, - DefaultVisual(globalconf.display, - phys_screen), - CWOverrideRedirect | - CWBackPixmap | - CWEventMask, - &wa); - - statusbar->drawable = XCreatePixmap(globalconf.display, - RootWindow(globalconf.display, phys_screen), - statusbar->width, statusbar->height, - DefaultDepth(globalconf.display, phys_screen)); - - - XDefineCursor(globalconf.display, - statusbar->window, - globalconf.cursor[CurNormal]); + statusbar->sw = + simplewindow_new(phys_screen, 0, 0, statusbar->width, statusbar->height, 0); widget_calculate_alignments(statusbar->widgets); statusbar_update_position(statusbar); - XMapRaised(globalconf.display, statusbar->window); statusbar_draw(statusbar); } diff --git a/structs.h b/structs.h index b57069ab6..36f074f42 100644 --- a/structs.h +++ b/structs.h @@ -127,9 +127,18 @@ struct Widget Widget *next; }; +/** A simple window */ +typedef struct SimpleWindow +{ + Window window; + Drawable drawable; +} SimpleWindow; + /** Status bar */ struct Statusbar { + /** Window */ + SimpleWindow *sw; /** Statusbar name */ char *name; /** Bar width */ @@ -142,14 +151,10 @@ struct Statusbar Position dposition; /** Bar position */ Position position; - /** Window */ - Window window; /** Screen */ int screen; /** Widget list */ Widget *widgets; - /** Drawable */ - Drawable drawable; /** Next statusbar */ Statusbar *next; }; diff --git a/window.c b/window.c index 328bc4f5c..a88dc3318 100644 --- a/window.c +++ b/window.c @@ -177,4 +177,48 @@ window_settrans(Window win, double opacity) return status; } +SimpleWindow * +simplewindow_new(int phys_screen, int x, int y, unsigned int w, unsigned int h, + unsigned int border_width) +{ + XSetWindowAttributes wa; + SimpleWindow *sw; + + sw = p_new(SimpleWindow, 1); + wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask + | EnterWindowMask | LeaveWindowMask | StructureNotifyMask; + wa.cursor = globalconf.cursor[CurNormal]; + wa.override_redirect = 1; + wa.background_pixmap = ParentRelative; + wa.event_mask = ButtonPressMask | ExposureMask; + sw->window = XCreateWindow(globalconf.display, + RootWindow(globalconf.display, phys_screen), + x, y, w, h, + border_width, + DefaultDepth(globalconf.display, phys_screen), + CopyFromParent, + DefaultVisual(globalconf.display, phys_screen), + CWOverrideRedirect | CWBackPixmap | CWEventMask, + &wa); + + sw->drawable = XCreatePixmap(globalconf.display, + RootWindow(globalconf.display, phys_screen), + w, h, + DefaultDepth(globalconf.display, phys_screen)); + + XDefineCursor(globalconf.display, + sw->window, + globalconf.cursor[CurNormal]); + + return sw; +} + +void +simplewindow_delete(SimpleWindow *sw) +{ + XDestroyWindow(globalconf.display, sw->window); + XFreePixmap(globalconf.display, sw->drawable); + p_delete(&sw); +} + // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/window.h b/window.h index ca5315a59..db7c74d4b 100644 --- a/window.h +++ b/window.h @@ -22,7 +22,7 @@ #ifndef AWESOME_WINDOW_H #define AWESOME_WINDOW_H -#include +#include "structs.h" int window_setstate(Window, long); long window_getstate(Window); @@ -30,6 +30,8 @@ Status window_configure(Window, Area, int); void window_grabbuttons(int, Window, Bool, Bool); void window_setshape(int, Window); int window_settrans(Window, double); +SimpleWindow * simplewindow_new(int, int, int, unsigned int, unsigned int, unsigned int); +void simplewindow_delete(SimpleWindow *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80