diff --git a/Makefile.am b/Makefile.am index bb3a6e5d..a25714e0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -126,6 +126,7 @@ awesome_SOURCES = \ rules.c rules.h \ mouse.c mouse.h \ common/awclient.c \ + common/swindow.c common/swindow.h \ widget.c widget.h \ ewmh.c ewmh.h \ common/list.h structs.h diff --git a/common/swindow.c b/common/swindow.c new file mode 100644 index 00000000..4c111516 --- /dev/null +++ b/common/swindow.c @@ -0,0 +1,93 @@ +/* + * swindow.c - simple window handling functions + * + * Copyright © 2008 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include + +#include "common/draw.h" +#include "common/swindow.h" +#include "common/util.h" + +SimpleWindow * +simplewindow_new(Display *disp, 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); + + sw->geometry.x = x; + sw->geometry.y = y; + sw->geometry.width = w; + sw->geometry.height = h; + sw->display = disp; + + wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask + | EnterWindowMask | LeaveWindowMask | StructureNotifyMask; + wa.override_redirect = 1; + wa.background_pixmap = ParentRelative; + wa.event_mask = ButtonPressMask | ExposureMask; + sw->window = XCreateWindow(disp, + RootWindow(disp, phys_screen), + x, y, w, h, + border_width, + DefaultDepth(disp, phys_screen), + CopyFromParent, + DefaultVisual(disp, phys_screen), + CWOverrideRedirect | CWBackPixmap | CWEventMask, + &wa); + + sw->drawable = XCreatePixmap(disp, + RootWindow(disp, phys_screen), + w, h, + DefaultDepth(disp, phys_screen)); + return sw; +} + +void +simplewindow_delete(SimpleWindow *sw) +{ + XDestroyWindow(sw->display, sw->window); + XFreePixmap(sw->display, sw->drawable); + p_delete(&sw); +} + +int +simplewindow_move(SimpleWindow *sw, int x, int y) +{ + sw->geometry.x = x; + sw->geometry.y = y; + return XMoveWindow(sw->display, sw->window, x, y); +} + +int +simplewindow_refresh_drawable(SimpleWindow *sw, int phys_screen) +{ + return XCopyArea(sw->display, sw->drawable, + sw->window, + DefaultGC(sw->display, phys_screen), 0, 0, + sw->geometry.width, + sw->geometry.height, + 0, 0); +} + +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/swindow.h b/common/swindow.h new file mode 100644 index 00000000..877f9399 --- /dev/null +++ b/common/swindow.h @@ -0,0 +1,40 @@ +/* + * swindow.h - simple window handling functions header + * + * Copyright © 2007-2008 Julien Danjou + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef AWESOME_COMMON_SWINDOW_H +#define AWESOME_COMMON_SWINDOW_H + +/** A simple window */ +typedef struct SimpleWindow +{ + Display *display; + Window window; + Drawable drawable; + Area geometry; +} SimpleWindow; + +SimpleWindow * simplewindow_new(Display *, int, int, int, unsigned int, unsigned int, unsigned int); +void simplewindow_delete(SimpleWindow *); +int simplewindow_move(SimpleWindow *, int, int); +int simplewindow_refresh_drawable(SimpleWindow *, int); + +#endif +// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/statusbar.c b/statusbar.c index 88a9f1d4..136766c7 100644 --- a/statusbar.c +++ b/statusbar.c @@ -215,11 +215,13 @@ statusbar_init(Statusbar *statusbar) case Right: case Left: statusbar->sw = - simplewindow_new(phys_screen, 0, 0, statusbar->height, statusbar->width, 0); + simplewindow_new(globalconf.display, phys_screen, 0, 0, + statusbar->height, statusbar->width, 0); break; default: statusbar->sw = - simplewindow_new(phys_screen, 0, 0, statusbar->width, statusbar->height, 0); + simplewindow_new(globalconf.display, phys_screen, 0, 0, + statusbar->width, statusbar->height, 0); break; } diff --git a/structs.h b/structs.h index 9821a57f..f83c3093 100644 --- a/structs.h +++ b/structs.h @@ -25,6 +25,7 @@ #include #include "layout.h" #include "common/draw.h" +#include "common/swindow.h" /** Bar possible position */ typedef enum @@ -128,14 +129,6 @@ struct Widget Widget *next; }; -/** A simple window */ -typedef struct SimpleWindow -{ - Window window; - Drawable drawable; - Area geometry; -} SimpleWindow; - /** Status bar */ struct Statusbar { diff --git a/window.c b/window.c index c2673854..2b3b416a 100644 --- a/window.c +++ b/window.c @@ -1,7 +1,7 @@ /* * window.c - window handling functions * - * Copyright © 2007 Julien Danjou + * Copyright © 2007-2008 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,6 +22,7 @@ #include #include +#include "structs.h" #include "window.h" #include "common/util.h" @@ -172,73 +173,4 @@ 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); - - sw->geometry.x = x; - sw->geometry.y = y; - sw->geometry.width = w; - sw->geometry.height = h; - - 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); -} - -int -simplewindow_move(SimpleWindow *sw, int x, int y) -{ - sw->geometry.x = x; - sw->geometry.y = y; - return XMoveWindow(globalconf.display, sw->window, x, y); -} - -int -simplewindow_refresh_drawable(SimpleWindow *sw, int phys_screen) -{ - return XCopyArea(globalconf.display, sw->drawable, - sw->window, - DefaultGC(globalconf.display, phys_screen), 0, 0, - sw->geometry.width, - sw->geometry.height, - 0, 0); -} - // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/window.h b/window.h index 04cec955..08578e20 100644 --- a/window.h +++ b/window.h @@ -1,7 +1,7 @@ /* * window.h - window handling functions header * - * Copyright © 2007 Julien Danjou + * Copyright © 2007-2008 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ #ifndef AWESOME_WINDOW_H #define AWESOME_WINDOW_H -#include "structs.h" +#include "common/draw.h" int window_setstate(Window, long); long window_getstate(Window); @@ -31,10 +31,6 @@ void window_grabbuttons(int, Window); void window_root_grabbuttons(int); 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 *); -int simplewindow_move(SimpleWindow *, int, int); -int simplewindow_refresh_drawable(SimpleWindow *, int); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80