From e028c2aca571a686cb3b1d5c8c5cc4de674847fd Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sun, 7 Aug 2011 23:26:06 +0200 Subject: [PATCH] add barwin --- wmfs2/src/barwin.c | 105 +++++++++++++++++++++++++++++++++++++++++++++ wmfs2/src/barwin.h | 31 +++++++++++++ wmfs2/src/client.c | 2 - wmfs2/src/wmfs.c | 2 + wmfs2/src/wmfs.h | 16 ++++++- 5 files changed, 153 insertions(+), 3 deletions(-) create mode 100755 wmfs2/src/barwin.c create mode 100755 wmfs2/src/barwin.h diff --git a/wmfs2/src/barwin.c b/wmfs2/src/barwin.c new file mode 100755 index 0000000..15d6b46 --- /dev/null +++ b/wmfs2/src/barwin.c @@ -0,0 +1,105 @@ +/* + * wmfs2 by Martin Duquesnoy { for(i = 2011; i < 2111; ++i) ©(i); } + * For license, see COPYING. + */ + +#include "wmfs.h" +#include "barwin.h" +#include "util.h" + +/** Create a Barwin + * \param parent Parent window of the BarWindow + * \param x X position + * \param y Y position + * \param w Barwin Width + * \param h Barwin Height + * \param color Barwin color + * \param entermask bool for know if the EnterMask mask is needed + * \return The BarWindow pointer +*/ +Barwin* +barwin_new(Window parent, int x, int y, int w, int h, Color fg, Color bg, bool entermask) +{ + Barwin *b; + XSetWindowAttributes at = + { + .override_redirect = True, + .background_pixmap = ParentRelative, + .event_mask = BARWIN_MASK + }; + + b = (Barwin*)xcalloc(1, sizeof(Barwin)); + + if(entermask) + at.event_mask |= BARWIN_ENTERMASK; + + /* Create window */ + b->win = XCreateWindow(W->dpy, parent, x, y, w, h, 0, W->xdepth, CopyFromParent, + DefaultVisual(W->dpy, W->xscreen), BARWIN_WINCW, &at); + + b->dr = XCreatePixmap(W->dpy, parent, w, h, W->xdepth); + + /* Property */ + b->geo.x = x; + b->geo.y = y; + b->geo.w = w; + b->geo.h = h; + b->bg = bg; + b->fg = fg; + + /* Attach */ + SLIST_INSERT_HEAD(&W->h.barwin, b, next); + + return b; +} + +/** Delete a Barwin + * \param bw Barwin pointer +*/ +void +barwin_remove(Barwin *b) +{ + SLIST_REMOVE(&W->h.barwin, b, Barwin, next); + + XSelectInput(W->dpy, b->win, NoEventMask); + XDestroyWindow(W->dpy, b->win); + XFreePixmap(W->dpy, b->dr); + + free(b); +} + +/** Resize a Barwin + * \param bw Barwin pointer + * \param w Width + * \param h Height +*/ +void +barwin_resize(Barwin *b, int w, int h) +{ + if(b->geo.w == w && b->geo.h == h) + return; + + /* Frame */ + XFreePixmap(W->dpy, b->dr); + + b->dr = XCreatePixmap(W->dpy, W->root, w, h, W->xdepth); + + b->geo.w = w; + b->geo.h = h; + + XResizeWindow(W->dpy, b->win, w, h); +} + + +/** Refresh the Barwin Color + * \param bw Barwin pointer +*/ +void +barwin_refresh_color(Barwin *b) +{ + XSetForeground(W->dpy, W->gc, b->bg); + XFillRectangle(W->dpy, b->dr, W->gc, 0, 0, b->geo.w, b->geo.h); +} + + + diff --git a/wmfs2/src/barwin.h b/wmfs2/src/barwin.h new file mode 100755 index 0000000..de03d88 --- /dev/null +++ b/wmfs2/src/barwin.h @@ -0,0 +1,31 @@ +/* + * wmfs2 by Martin Duquesnoy { for(i = 2011; i < 2111; ++i) ©(i); } + * For license, see COPYING. + */ + +#ifndef BARWIN_H +#define BARWIN_H + +#include "wmfs.h" + +#define BARWIN_MASK \ + (SubstructureRedirectMask | SubstructureNotifyMask \ + | ButtonMask | MouseMask | ExposureMask | VisibilityChangeMask \ + | StructureNotifyMask | SubstructureRedirectMask) + +#define BARWIN_ENTERMASK (EnterWindowMask | LeaveWindowMask | FocusChangeMask) +#define BARWIN_WINCW (CWOverrideRedirect | CWBackPixmap | CWEventMask) + +#define barwin_delete_subwin(b) XDestroySubwindows(W->dpy, b->win) +#define barwin_map_subwin(b) XMapSubwindows(W->dpy, b->win) +#define barwin_unmap_subwin(b) XUnmapSubwindows(W->dpy, b->win) +#define barwin_refresh(b) XCopyArea(W->dpy, b->dr, b->win, W->gc, 0, 0, b->geo.w, b->geo.h, 0, 0) +#define barwin_map(b) XMapWindow(W->dpy, b->win); +#define barwin_unmap(b) XUnmapWindow(W->dpy, b->win); + +Barwin* barwin_new(Window parent, int x, int y, int w, int h, Color fg, Color bg, bool entermask); +void barwin_remove(Barwin *b); +void barwin_resize(Barwin *b, int w, int h); +void barwin_refresh_color(Barwin *b); + +#endif /* BARWIN_H */ diff --git a/wmfs2/src/client.c b/wmfs2/src/client.c index 9f0d513..e608561 100755 --- a/wmfs2/src/client.c +++ b/wmfs2/src/client.c @@ -61,8 +61,6 @@ client_unmap(Client *c) void client_focus(Client *c) { - puts("foc"); - /* Unfocus selected */ if(c->tag->sel && c->tag->sel != c) { diff --git a/wmfs2/src/wmfs.c b/wmfs2/src/wmfs.c index 1bbcc21..a7ea899 100755 --- a/wmfs2/src/wmfs.c +++ b/wmfs2/src/wmfs.c @@ -8,6 +8,7 @@ #include "wmfs.h" #include "event.h" +#include "util.h" int wmfs_error_handler(Display *d, XErrorEvent *event) @@ -68,6 +69,7 @@ wmfs_xinit(void) * X var */ W->xscreen = DefaultScreen(W->dpy); + W->xdepth = DefaultDepth(W->dpy, W->xscreen); W->gc = DefaultGC(W->dpy, W->xscreen); /* diff --git a/wmfs2/src/wmfs.h b/wmfs2/src/wmfs.h index 3c9a394..f568a44 100755 --- a/wmfs2/src/wmfs.h +++ b/wmfs2/src/wmfs.h @@ -28,12 +28,14 @@ #define KeyMask (KeyPressMask | KeyReleaseMask) typedef unsigned int Flags; +typedef unsigned int Color; typedef const char* Uicb; /* * Structures */ typedef struct Geo Geo; +typedef struct Barwin Barwin; typedef struct Scr33n Scr33n; typedef struct Tag Tag; typedef struct Client Client; @@ -44,6 +46,17 @@ struct Geo int x, y, w, h; }; +/* Barwin */ +struct Barwin +{ + Window win; + Drawable dr; + Color fg, bg; + Geo geo; + Flags flags; + SLIST_ENTRY(Barwin) next; +}; + /* Screen */ struct Scr33n { @@ -92,7 +105,7 @@ struct Wmfs bool running; Display *dpy; Window root; - int xscreen; + int xscreen, xdepth; Flags numlockmask; GC gc; Atom *net_atom; @@ -109,6 +122,7 @@ struct Wmfs SLIST_HEAD(, Scr33n) screen; SLIST_HEAD(, Client) client; SLIST_HEAD(, Keybind) keybind; + SLIST_HEAD(, Barwin) barwin; } h; /*