From af6ff367eb64efe48936208036319441c78488b6 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 4 Jan 2008 19:12:07 +0100 Subject: [PATCH] typedef enum Position --- config.h | 14 ++++++++++---- event.c | 6 +++--- screen.c | 14 ++++++++------ statusbar.c | 44 ++++++++++++++++++++++---------------------- statusbar.h | 2 +- widgets/taglist.c | 18 ++++++++++-------- widgets/tasklist.c | 15 ++++++++++----- 7 files changed, 64 insertions(+), 49 deletions(-) diff --git a/config.h b/config.h index 384bc007..469034ce 100644 --- a/config.h +++ b/config.h @@ -27,8 +27,14 @@ #include "layout.h" /** Bar possible position */ -enum -{ BarTop, BarBot, BarLeft, BarRight, BarOff }; +typedef enum +{ + Top, + Bottom, + Left, + Right, + Off +} Position; /** Common colors */ enum @@ -124,9 +130,9 @@ struct Statusbar /** Layout txt width */ int txtlayoutwidth; /** Default position */ - int dposition; + Position dposition; /** Bar position */ - int position; + Position position; /** Window */ Window window; /** Screen */ diff --git a/event.c b/event.c index a9826279..dfb4fa70 100644 --- a/event.c +++ b/event.c @@ -72,8 +72,8 @@ handle_event_buttonpress(XEvent *e) for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next) if(statusbar->window == ev->window) { - if(statusbar->position == BarTop - || globalconf.screens[screen].statusbar->position == BarBot) + if(statusbar->position == Top + || globalconf.screens[screen].statusbar->position == Bottom) { for(widget = statusbar->widgets; widget; widget = widget->next) if(ev->x >= widget->location && ev->x <= widget->location + widget->width) @@ -82,7 +82,7 @@ handle_event_buttonpress(XEvent *e) return; } } - else if(statusbar->position == BarRight) + else if(statusbar->position == Right) { for(widget = statusbar->widgets; widget; widget = widget->next) if(ev->y >= widget->location && ev->y <= widget->location + widget->width) diff --git a/screen.c b/screen.c index 0da0bee0..def89a1c 100644 --- a/screen.c +++ b/screen.c @@ -76,16 +76,18 @@ get_screen_area(int screen, Statusbar *statusbar, Padding *padding) for(sb = statusbar; sb; sb = sb->next) switch(sb->position) { - case BarTop: + case Top: area.y += sb->height; - case BarBot: + case Bottom: area.height -= sb->height; break; - case BarLeft: + case Left: area.x += sb->height; - case BarRight: + case Right: area.width -= sb->height; break; + case Off: + break; } return area; @@ -110,8 +112,8 @@ get_display_area(int screen, Statusbar *statusbar, Padding *padding) for(sb = statusbar; sb; sb = sb->next) { - area.y += sb->position == BarTop ? sb->height : 0; - area.height -= (sb->position == BarTop || sb->position == BarBot) ? sb->height : 0; + area.y += sb->position == Top ? sb->height : 0; + area.height -= (sb->position == Top || sb->position == Bottom) ? sb->height : 0; } /* make padding corrections */ diff --git a/statusbar.c b/statusbar.c index f264188e..4b7b1902 100644 --- a/statusbar.c +++ b/statusbar.c @@ -38,7 +38,7 @@ statusbar_draw(Statusbar *statusbar) int left = 0, right = 0; /* don't waste our time */ - if(statusbar->position == BarOff) + if(statusbar->position == Off) return; XFreePixmap(globalconf.display, statusbar->drawable); @@ -67,11 +67,11 @@ statusbar_draw(Statusbar *statusbar) if (widget->alignment == AlignFlex) left += widget->draw(widget, ctx, left, (left + right)); - if(statusbar->position == BarRight - || statusbar->position == BarLeft) + if(statusbar->position == Right + || statusbar->position == Left) { Drawable d; - if(statusbar->position == BarRight) + if(statusbar->position == Right) d = draw_rotate(ctx, phys_screen, M_PI_2, statusbar->height, 0); else 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); /* don't waste our time */ - if(statusbar->position == BarOff) + if(statusbar->position == Off) return; - if(statusbar->position == BarRight - || statusbar->position == BarLeft) + if(statusbar->position == Right + || statusbar->position == Left) XCopyArea(globalconf.display, statusbar->drawable, statusbar->window, DefaultGC(globalconf.display, phys_screen), 0, 0, @@ -143,7 +143,7 @@ statusbar_init(Statusbar *statusbar, int screen) if(statusbar->width <= 0) { - if(statusbar->position == BarRight || statusbar->position == BarLeft) + if(statusbar->position == Right || statusbar->position == Left) statusbar->width = area.height; else statusbar->width = area.width; @@ -157,7 +157,7 @@ statusbar_init(Statusbar *statusbar, int screen) wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ButtonPressMask | ExposureMask; - if(statusbar->dposition == BarRight || statusbar->dposition == BarLeft) + if(statusbar->dposition == Right || statusbar->dposition == Left) statusbar->window = XCreateWindow(globalconf.display, RootWindow(globalconf.display, phys_screen), @@ -225,19 +225,19 @@ statusbar_update_position(Statusbar *statusbar) XMoveWindow(globalconf.display, statusbar->window, area.x, area.y); break; - case BarLeft: + case Left: XMoveWindow(globalconf.display, statusbar->window, area.x, (area.y + area.height) - statusbar->width); break; - case BarRight: + case Right: XMoveWindow(globalconf.display, statusbar->window, area.x + (area.width - statusbar->height), area.y); break; - case BarBot: + case Bottom: XMoveWindow(globalconf.display, statusbar->window, area.x, area.height - statusbar->height); break; - case BarOff: + case Off: XUnmapWindow(globalconf.display, statusbar->window); break; } @@ -245,18 +245,18 @@ statusbar_update_position(Statusbar *statusbar) while(XCheckMaskEvent(globalconf.display, EnterWindowMask, &ev)); } -int +Position statusbar_get_position_from_str(const char *pos) { if(!a_strncmp(pos, "off", 3)) - return BarOff; + return Off; else if(!a_strncmp(pos, "bottom", 6)) - return BarBot; + return Bottom; else if(!a_strncmp(pos, "right", 5)) - return BarRight; + return Right; else if(!a_strncmp(pos, "left", 4)) - return BarLeft; - return BarTop; + return Left; + return Top; } static Statusbar * @@ -275,10 +275,10 @@ get_statusbar_byname(int screen, const char *name) static void statusbar_toggle(Statusbar *statusbar) { - if(statusbar->position == BarOff) - statusbar->position = (statusbar->dposition == BarOff) ? BarTop : statusbar->dposition; + if(statusbar->position == Off) + statusbar->position = (statusbar->dposition == Off) ? Top : statusbar->dposition; else - statusbar->position = BarOff; + statusbar->position = Off; statusbar_update_position(statusbar); } diff --git a/statusbar.h b/statusbar.h index d42447b2..3774e0a0 100644 --- a/statusbar.h +++ b/statusbar.h @@ -27,7 +27,7 @@ void statusbar_draw_all(int); void statusbar_init(Statusbar *, int); 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 *); Uicb uicb_statusbar_toggle; diff --git a/widgets/taglist.c b/widgets/taglist.c index 504ef1c6..252889fd 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -119,9 +119,10 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev) for(b = widget->buttons; b; b = b->next) if(ev->button == b->button && CLEANMASK(ev->state) == b->mod && b->func) - { - if(widget->statusbar->position == BarTop - || widget->statusbar->position == BarBot) + switch(widget->statusbar->position) + { + case Top: + case Bottom: for(tag = vscreen.tags; tag; tag = tag->next, i++) { width = textwidth(vscreen.font, tag->name) + vscreen.font->height; @@ -134,7 +135,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev) } prev_width += width; } - else if(widget->statusbar->position == BarRight) + break; + case Right: for(tag = vscreen.tags; tag; tag = tag->next, i++) { width = textwidth(vscreen.font, tag->name) + vscreen.font->height; @@ -147,7 +149,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev) } prev_width += width; } - else + break; + default: for(tag = vscreen.tags; tag; tag = tag->next, i++) { width = textwidth(vscreen.font, tag->name) + vscreen.font->height; @@ -160,9 +163,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev) } prev_width += width; } - } - - + break; + } } Widget * diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 831b290c..10aa1f68 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -152,14 +152,19 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev) if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol) { - if(widget->statusbar->position == BarTop - || widget->statusbar->position == BarBot) + switch(widget->statusbar->position) + { + case Top: + case Bottom: ci = (ev->x - widget->location) / box_width; - else if(widget->statusbar->position == BarRight) + break; + case Right: ci = (ev->y - widget->location) / box_width; - else + break; + default: ci = ((widget->statusbar->width - ev->y) - widget->location) / box_width; - + break; + } /* found first visible client */ for(c = globalconf.clients; c && !ISVISIBLE_ON_TB(c, widget->statusbar->screen);