add some code for creating SimpleWindow-s and use it for statusbar

This commit is contained in:
Julien Danjou 2008-01-23 15:54:30 +01:00
parent e7447c24d3
commit 5fa25b23f6
5 changed files with 78 additions and 72 deletions

View File

@ -72,7 +72,7 @@ handle_event_buttonpress(XEvent *e)
for(screen = 0; screen < globalconf.nscreens; screen++) for(screen = 0; screen < globalconf.nscreens; screen++)
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) 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) switch(statusbar->position)
{ {
case Top: case Top:
@ -204,7 +204,7 @@ handle_event_configurenotify(XEvent * e)
globalconf.screens[screen].statusbar->width = area.width; globalconf.screens[screen].statusbar->width = area.width;
XResizeWindow(e->xany.display, XResizeWindow(e->xany.display,
globalconf.screens[screen].statusbar->window, globalconf.screens[screen].statusbar->sw->window,
globalconf.screens[screen].statusbar->width, globalconf.screens[screen].statusbar->width,
globalconf.screens[screen].statusbar->height); globalconf.screens[screen].statusbar->height);
@ -261,7 +261,7 @@ handle_event_expose(XEvent *e)
if(!ev->count) if(!ev->count)
for(screen = 0; screen < globalconf.nscreens; screen++) for(screen = 0; screen < globalconf.nscreens; screen++)
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
if(statusbar->window == ev->window) if(statusbar->sw->window == ev->window)
{ {
statusbar_display(statusbar); statusbar_display(statusbar);
return; return;

View File

@ -26,6 +26,7 @@
#include "screen.h" #include "screen.h"
#include "tag.h" #include "tag.h"
#include "widget.h" #include "widget.h"
#include "window.h"
#include "common/util.h" #include "common/util.h"
extern AwesomeConf globalconf; extern AwesomeConf globalconf;
@ -35,7 +36,7 @@ statusbar_update_position(Statusbar *statusbar)
{ {
Area area; Area area;
XMapRaised(globalconf.display, statusbar->window); XMapRaised(globalconf.display, statusbar->sw->window);
/* Top and Bottom Statusbar have prio */ /* Top and Bottom Statusbar have prio */
if(statusbar->position == Top || statusbar->position == Bottom) if(statusbar->position == Top || statusbar->position == Bottom)
@ -50,23 +51,23 @@ statusbar_update_position(Statusbar *statusbar)
switch(statusbar->position) switch(statusbar->position)
{ {
case Top: case Top:
XMoveWindow(globalconf.display, statusbar->window, XMoveWindow(globalconf.display, statusbar->sw->window,
area.x, area.y); area.x, area.y);
break; break;
case Bottom: case Bottom:
XMoveWindow(globalconf.display, statusbar->window, XMoveWindow(globalconf.display, statusbar->sw->window,
area.x, area.height - statusbar->height); area.x, area.height - statusbar->height);
break; break;
case Left: case Left:
XMoveWindow(globalconf.display, statusbar->window, XMoveWindow(globalconf.display, statusbar->sw->window,
area.x - statusbar->height, (area.y + area.height) - statusbar->width); area.x - statusbar->height, (area.y + area.height) - statusbar->width);
break; break;
case Right: case Right:
XMoveWindow(globalconf.display, statusbar->window, XMoveWindow(globalconf.display, statusbar->sw->window,
area.x + area.width, area.y); area.x + area.width, area.y);
break; break;
case Off: case Off:
XUnmapWindow(globalconf.display, statusbar->window); XUnmapWindow(globalconf.display, statusbar->sw->window);
break; break;
} }
} }
@ -83,7 +84,7 @@ statusbar_draw(Statusbar *statusbar)
if(statusbar->position == Off) if(statusbar->position == Off)
return; return;
XFreePixmap(globalconf.display, statusbar->drawable); XFreePixmap(globalconf.display, statusbar->sw->drawable);
DrawCtx *ctx = draw_get_context(phys_screen, DrawCtx *ctx = draw_get_context(phys_screen,
statusbar->width, statusbar->width,
@ -122,15 +123,15 @@ statusbar_draw(Statusbar *statusbar)
|| statusbar->position == Left) || statusbar->position == Left)
{ {
if(statusbar->position == Right) 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 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); draw_free_context(ctx);
} }
else else
{ {
statusbar->drawable = ctx->drawable; statusbar->sw->drawable = ctx->drawable;
/* just delete the struct, don't delete the drawable */ /* just delete the struct, don't delete the drawable */
p_delete(&ctx); p_delete(&ctx);
} }
@ -149,14 +150,14 @@ statusbar_display(Statusbar *statusbar)
if(statusbar->position == Right if(statusbar->position == Right
|| statusbar->position == Left) || statusbar->position == Left)
XCopyArea(globalconf.display, statusbar->drawable, XCopyArea(globalconf.display, statusbar->sw->drawable,
statusbar->window, statusbar->sw->window,
DefaultGC(globalconf.display, phys_screen), 0, 0, DefaultGC(globalconf.display, phys_screen), 0, 0,
statusbar->height, statusbar->height,
statusbar->width, 0, 0); statusbar->width, 0, 0);
else else
XCopyArea(globalconf.display, statusbar->drawable, XCopyArea(globalconf.display, statusbar->sw->drawable,
statusbar->window, statusbar->sw->window,
DefaultGC(globalconf.display, phys_screen), 0, 0, DefaultGC(globalconf.display, phys_screen), 0, 0,
statusbar->width, statusbar->height, 0, 0); statusbar->width, statusbar->height, 0, 0);
} }
@ -181,7 +182,6 @@ void
statusbar_init(Statusbar *statusbar) statusbar_init(Statusbar *statusbar)
{ {
Statusbar *sb; Statusbar *sb;
XSetWindowAttributes wa;
int phys_screen = get_phys_screen(statusbar->screen); int phys_screen = get_phys_screen(statusbar->screen);
Area area = get_screen_area(statusbar->screen, Area area = get_screen_area(statusbar->screen,
globalconf.screens[statusbar->screen].statusbar, globalconf.screens[statusbar->screen].statusbar,
@ -208,61 +208,16 @@ statusbar_init(Statusbar *statusbar)
statusbar->width = area.width; 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) if(statusbar->dposition == Right || statusbar->dposition == Left)
statusbar->window = XCreateWindow(globalconf.display, statusbar->sw =
RootWindow(globalconf.display, simplewindow_new(phys_screen, 0, 0, statusbar->height, statusbar->width, 0);
phys_screen),
0, 0,
statusbar->height,
statusbar->width,
0,
DefaultDepth(globalconf.display,
phys_screen),
CopyFromParent,
DefaultVisual(globalconf.display,
phys_screen),
CWOverrideRedirect |
CWBackPixmap |
CWEventMask,
&wa);
else else
statusbar->window = XCreateWindow(globalconf.display, statusbar->sw =
RootWindow(globalconf.display, simplewindow_new(phys_screen, 0, 0, statusbar->width, statusbar->height, 0);
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]);
widget_calculate_alignments(statusbar->widgets); widget_calculate_alignments(statusbar->widgets);
statusbar_update_position(statusbar); statusbar_update_position(statusbar);
XMapRaised(globalconf.display, statusbar->window);
statusbar_draw(statusbar); statusbar_draw(statusbar);
} }

View File

@ -127,9 +127,18 @@ struct Widget
Widget *next; Widget *next;
}; };
/** A simple window */
typedef struct SimpleWindow
{
Window window;
Drawable drawable;
} SimpleWindow;
/** Status bar */ /** Status bar */
struct Statusbar struct Statusbar
{ {
/** Window */
SimpleWindow *sw;
/** Statusbar name */ /** Statusbar name */
char *name; char *name;
/** Bar width */ /** Bar width */
@ -142,14 +151,10 @@ struct Statusbar
Position dposition; Position dposition;
/** Bar position */ /** Bar position */
Position position; Position position;
/** Window */
Window window;
/** Screen */ /** Screen */
int screen; int screen;
/** Widget list */ /** Widget list */
Widget *widgets; Widget *widgets;
/** Drawable */
Drawable drawable;
/** Next statusbar */ /** Next statusbar */
Statusbar *next; Statusbar *next;
}; };

View File

@ -177,4 +177,48 @@ window_settrans(Window win, double opacity)
return status; 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 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80

View File

@ -22,7 +22,7 @@
#ifndef AWESOME_WINDOW_H #ifndef AWESOME_WINDOW_H
#define AWESOME_WINDOW_H #define AWESOME_WINDOW_H
#include <X11/Xlib.h> #include "structs.h"
int window_setstate(Window, long); int window_setstate(Window, long);
long window_getstate(Window); long window_getstate(Window);
@ -30,6 +30,8 @@ Status window_configure(Window, Area, int);
void window_grabbuttons(int, Window, Bool, Bool); void window_grabbuttons(int, Window, Bool, Bool);
void window_setshape(int, Window); void window_setshape(int, Window);
int window_settrans(Window, double); int window_settrans(Window, double);
SimpleWindow * simplewindow_new(int, int, int, unsigned int, unsigned int, unsigned int);
void simplewindow_delete(SimpleWindow *);
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80