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(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;

View File

@ -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);
}

View File

@ -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;
};

View File

@ -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

View File

@ -22,7 +22,7 @@
#ifndef AWESOME_WINDOW_H
#define AWESOME_WINDOW_H
#include <X11/Xlib.h>
#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