typedef enum Position

This commit is contained in:
Julien Danjou 2008-01-04 19:12:07 +01:00
parent 343c6c7df0
commit af6ff367eb
7 changed files with 64 additions and 49 deletions

View File

@ -27,8 +27,14 @@
#include "layout.h" #include "layout.h"
/** Bar possible position */ /** Bar possible position */
enum typedef enum
{ BarTop, BarBot, BarLeft, BarRight, BarOff }; {
Top,
Bottom,
Left,
Right,
Off
} Position;
/** Common colors */ /** Common colors */
enum enum
@ -124,9 +130,9 @@ struct Statusbar
/** Layout txt width */ /** Layout txt width */
int txtlayoutwidth; int txtlayoutwidth;
/** Default position */ /** Default position */
int dposition; Position dposition;
/** Bar position */ /** Bar position */
int position; Position position;
/** Window */ /** Window */
Window window; Window window;
/** Screen */ /** Screen */

View File

@ -72,8 +72,8 @@ handle_event_buttonpress(XEvent *e)
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->window == ev->window)
{ {
if(statusbar->position == BarTop if(statusbar->position == Top
|| globalconf.screens[screen].statusbar->position == BarBot) || globalconf.screens[screen].statusbar->position == Bottom)
{ {
for(widget = statusbar->widgets; widget; widget = widget->next) for(widget = statusbar->widgets; widget; widget = widget->next)
if(ev->x >= widget->location && ev->x <= widget->location + widget->width) if(ev->x >= widget->location && ev->x <= widget->location + widget->width)
@ -82,7 +82,7 @@ handle_event_buttonpress(XEvent *e)
return; return;
} }
} }
else if(statusbar->position == BarRight) else if(statusbar->position == Right)
{ {
for(widget = statusbar->widgets; widget; widget = widget->next) for(widget = statusbar->widgets; widget; widget = widget->next)
if(ev->y >= widget->location && ev->y <= widget->location + widget->width) if(ev->y >= widget->location && ev->y <= widget->location + widget->width)

View File

@ -76,16 +76,18 @@ get_screen_area(int screen, Statusbar *statusbar, Padding *padding)
for(sb = statusbar; sb; sb = sb->next) for(sb = statusbar; sb; sb = sb->next)
switch(sb->position) switch(sb->position)
{ {
case BarTop: case Top:
area.y += sb->height; area.y += sb->height;
case BarBot: case Bottom:
area.height -= sb->height; area.height -= sb->height;
break; break;
case BarLeft: case Left:
area.x += sb->height; area.x += sb->height;
case BarRight: case Right:
area.width -= sb->height; area.width -= sb->height;
break; break;
case Off:
break;
} }
return area; return area;
@ -110,8 +112,8 @@ get_display_area(int screen, Statusbar *statusbar, Padding *padding)
for(sb = statusbar; sb; sb = sb->next) for(sb = statusbar; sb; sb = sb->next)
{ {
area.y += sb->position == BarTop ? sb->height : 0; area.y += sb->position == Top ? sb->height : 0;
area.height -= (sb->position == BarTop || sb->position == BarBot) ? sb->height : 0; area.height -= (sb->position == Top || sb->position == Bottom) ? sb->height : 0;
} }
/* make padding corrections */ /* make padding corrections */

View File

@ -38,7 +38,7 @@ statusbar_draw(Statusbar *statusbar)
int left = 0, right = 0; int left = 0, right = 0;
/* don't waste our time */ /* don't waste our time */
if(statusbar->position == BarOff) if(statusbar->position == Off)
return; return;
XFreePixmap(globalconf.display, statusbar->drawable); XFreePixmap(globalconf.display, statusbar->drawable);
@ -67,11 +67,11 @@ statusbar_draw(Statusbar *statusbar)
if (widget->alignment == AlignFlex) if (widget->alignment == AlignFlex)
left += widget->draw(widget, ctx, left, (left + right)); left += widget->draw(widget, ctx, left, (left + right));
if(statusbar->position == BarRight if(statusbar->position == Right
|| statusbar->position == BarLeft) || statusbar->position == Left)
{ {
Drawable d; Drawable d;
if(statusbar->position == BarRight) if(statusbar->position == Right)
d = draw_rotate(ctx, phys_screen, M_PI_2, statusbar->height, 0); d = draw_rotate(ctx, phys_screen, M_PI_2, statusbar->height, 0);
else else
d = draw_rotate(ctx, phys_screen, - M_PI_2, 0, statusbar->width); d = draw_rotate(ctx, phys_screen, - M_PI_2, 0, statusbar->width);
@ -104,11 +104,11 @@ statusbar_display(Statusbar *statusbar)
int phys_screen = get_phys_screen(statusbar->screen); int phys_screen = get_phys_screen(statusbar->screen);
/* don't waste our time */ /* don't waste our time */
if(statusbar->position == BarOff) if(statusbar->position == Off)
return; return;
if(statusbar->position == BarRight if(statusbar->position == Right
|| statusbar->position == BarLeft) || statusbar->position == Left)
XCopyArea(globalconf.display, statusbar->drawable, XCopyArea(globalconf.display, statusbar->drawable,
statusbar->window, statusbar->window,
DefaultGC(globalconf.display, phys_screen), 0, 0, DefaultGC(globalconf.display, phys_screen), 0, 0,
@ -143,7 +143,7 @@ statusbar_init(Statusbar *statusbar, int screen)
if(statusbar->width <= 0) if(statusbar->width <= 0)
{ {
if(statusbar->position == BarRight || statusbar->position == BarLeft) if(statusbar->position == Right || statusbar->position == Left)
statusbar->width = area.height; statusbar->width = area.height;
else else
statusbar->width = area.width; statusbar->width = area.width;
@ -157,7 +157,7 @@ statusbar_init(Statusbar *statusbar, int screen)
wa.override_redirect = 1; wa.override_redirect = 1;
wa.background_pixmap = ParentRelative; wa.background_pixmap = ParentRelative;
wa.event_mask = ButtonPressMask | ExposureMask; wa.event_mask = ButtonPressMask | ExposureMask;
if(statusbar->dposition == BarRight || statusbar->dposition == BarLeft) if(statusbar->dposition == Right || statusbar->dposition == Left)
statusbar->window = XCreateWindow(globalconf.display, statusbar->window = XCreateWindow(globalconf.display,
RootWindow(globalconf.display, RootWindow(globalconf.display,
phys_screen), phys_screen),
@ -225,19 +225,19 @@ statusbar_update_position(Statusbar *statusbar)
XMoveWindow(globalconf.display, statusbar->window, XMoveWindow(globalconf.display, statusbar->window,
area.x, area.y); area.x, area.y);
break; break;
case BarLeft: case Left:
XMoveWindow(globalconf.display, statusbar->window, XMoveWindow(globalconf.display, statusbar->window,
area.x, (area.y + area.height) - statusbar->width); area.x, (area.y + area.height) - statusbar->width);
break; break;
case BarRight: case Right:
XMoveWindow(globalconf.display, statusbar->window, XMoveWindow(globalconf.display, statusbar->window,
area.x + (area.width - statusbar->height), area.y); area.x + (area.width - statusbar->height), area.y);
break; break;
case BarBot: case Bottom:
XMoveWindow(globalconf.display, statusbar->window, XMoveWindow(globalconf.display, statusbar->window,
area.x, area.height - statusbar->height); area.x, area.height - statusbar->height);
break; break;
case BarOff: case Off:
XUnmapWindow(globalconf.display, statusbar->window); XUnmapWindow(globalconf.display, statusbar->window);
break; break;
} }
@ -245,18 +245,18 @@ statusbar_update_position(Statusbar *statusbar)
while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev)); while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev));
} }
int Position
statusbar_get_position_from_str(const char *pos) statusbar_get_position_from_str(const char *pos)
{ {
if(!a_strncmp(pos, "off", 3)) if(!a_strncmp(pos, "off", 3))
return BarOff; return Off;
else if(!a_strncmp(pos, "bottom", 6)) else if(!a_strncmp(pos, "bottom", 6))
return BarBot; return Bottom;
else if(!a_strncmp(pos, "right", 5)) else if(!a_strncmp(pos, "right", 5))
return BarRight; return Right;
else if(!a_strncmp(pos, "left", 4)) else if(!a_strncmp(pos, "left", 4))
return BarLeft; return Left;
return BarTop; return Top;
} }
static Statusbar * static Statusbar *
@ -275,10 +275,10 @@ get_statusbar_byname(int screen, const char *name)
static void static void
statusbar_toggle(Statusbar *statusbar) statusbar_toggle(Statusbar *statusbar)
{ {
if(statusbar->position == BarOff) if(statusbar->position == Off)
statusbar->position = (statusbar->dposition == BarOff) ? BarTop : statusbar->dposition; statusbar->position = (statusbar->dposition == Off) ? Top : statusbar->dposition;
else else
statusbar->position = BarOff; statusbar->position = Off;
statusbar_update_position(statusbar); statusbar_update_position(statusbar);
} }

View File

@ -27,7 +27,7 @@
void statusbar_draw_all(int); void statusbar_draw_all(int);
void statusbar_init(Statusbar *, int); void statusbar_init(Statusbar *, int);
void statusbar_display(Statusbar *); void statusbar_display(Statusbar *);
int statusbar_get_position_from_str(const char *); Position statusbar_get_position_from_str(const char *);
void statusbar_update_position(Statusbar *); void statusbar_update_position(Statusbar *);
Uicb uicb_statusbar_toggle; Uicb uicb_statusbar_toggle;

View File

@ -119,9 +119,10 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
for(b = widget->buttons; b; b = b->next) for(b = widget->buttons; b; b = b->next)
if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func) if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func)
{ switch(widget->statusbar->position)
if(widget->statusbar->position == BarTop {
|| widget->statusbar->position == BarBot) case Top:
case Bottom:
for(tag = vscreen.tags; tag; tag = tag->next, i++) for(tag = vscreen.tags; tag; tag = tag->next, i++)
{ {
width = textwidth(vscreen.font, tag->name) + vscreen.font->height; width = textwidth(vscreen.font, tag->name) + vscreen.font->height;
@ -134,7 +135,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
} }
prev_width += width; prev_width += width;
} }
else if(widget->statusbar->position == BarRight) break;
case Right:
for(tag = vscreen.tags; tag; tag = tag->next, i++) for(tag = vscreen.tags; tag; tag = tag->next, i++)
{ {
width = textwidth(vscreen.font, tag->name) + vscreen.font->height; width = textwidth(vscreen.font, tag->name) + vscreen.font->height;
@ -147,7 +149,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
} }
prev_width += width; prev_width += width;
} }
else break;
default:
for(tag = vscreen.tags; tag; tag = tag->next, i++) for(tag = vscreen.tags; tag; tag = tag->next, i++)
{ {
width = textwidth(vscreen.font, tag->name) + vscreen.font->height; width = textwidth(vscreen.font, tag->name) + vscreen.font->height;
@ -160,9 +163,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
} }
prev_width += width; prev_width += width;
} }
} break;
}
} }
Widget * Widget *

View File

@ -152,14 +152,19 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev)
if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol) if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol)
{ {
if(widget->statusbar->position == BarTop switch(widget->statusbar->position)
|| widget->statusbar->position == BarBot) {
case Top:
case Bottom:
ci = (ev->x - widget->location) / box_width; ci = (ev->x - widget->location) / box_width;
else if(widget->statusbar->position == BarRight) break;
case Right:
ci = (ev->y - widget->location) / box_width; ci = (ev->y - widget->location) / box_width;
else break;
default:
ci = ((widget->statusbar->width - ev->y) - widget->location) / box_width; ci = ((widget->statusbar->width - ev->y) - widget->location) / box_width;
break;
}
/* found first visible client */ /* found first visible client */
for(c = globalconf.clients; for(c = globalconf.clients;
c && !ISVISIBLE_ON_TB(c, widget->statusbar->screen); c && !ISVISIBLE_ON_TB(c, widget->statusbar->screen);