From 05dad60786b2fbbb9fbf7d1b963db5348a1c8d42 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 11 Nov 2007 18:59:11 +0100 Subject: [PATCH] experimental support for status bar to be on right or left --- config.c | 4 +++ config.h | 2 +- draw.c | 19 ++++++++++++++ draw.h | 1 + screen.c | 18 +++++++++----- statusbar.c | 71 +++++++++++++++++++++++++++++++++++++++++------------ 6 files changed, 92 insertions(+), 23 deletions(-) diff --git a/config.c b/config.c index e79e5597..411c85af 100644 --- a/config.c +++ b/config.c @@ -370,6 +370,10 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) awesomeconf->statusbar.dposition = BarOff; else if(tmp && !a_strncmp(tmp, "bottom", 6)) awesomeconf->statusbar.dposition = BarBot; + else if(tmp && !a_strncmp(tmp, "right", 5)) + awesomeconf->statusbar.dposition = BarRight; + else if(tmp && !a_strncmp(tmp, "left", 4)) + awesomeconf->statusbar.dposition = BarLeft; else awesomeconf->statusbar.dposition = BarTop; diff --git a/config.h b/config.h index b8df1d72..fe0577a6 100644 --- a/config.h +++ b/config.h @@ -28,7 +28,7 @@ /** Bar possible position */ enum -{ BarTop, BarBot, BarOff }; +{ BarTop, BarBot, BarLeft, BarRight, BarOff }; enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ diff --git a/draw.c b/draw.c index 450bc589..a5480d80 100644 --- a/draw.c +++ b/draw.c @@ -125,6 +125,25 @@ drawcircle(Display *disp, int screen, int x, int y, int r, Drawable drawable, in cairo_surface_destroy(surface); } +void +draw_rotate(Display *disp, int screen, Drawable drawable, int dw, int dh, double angle) +{ + cairo_surface_t *surface, *source; + cairo_t *cr; + + surface = cairo_xlib_surface_create(disp, drawable, DefaultVisual(disp, screen), dw, dw); + source = cairo_xlib_surface_create(disp, drawable, DefaultVisual(disp, screen), dw, dw); + cr = cairo_create (surface); + cairo_rotate(cr, M_PI / 2); + cairo_translate(cr, 0.0, -dh); + + cairo_set_source_surface(cr, source, 0.0, 0.0); + cairo_paint_with_alpha(cr, 1.0); + + cairo_destroy(cr); + cairo_surface_destroy(source); +} + unsigned short textwidth(Display *disp, XftFont *font, char *text) { diff --git a/draw.h b/draw.h index 333b207d..52487f4b 100644 --- a/draw.h +++ b/draw.h @@ -27,6 +27,7 @@ void drawtext(Display *, int, int, int, int, int, Drawable, int, int, XftFont *, const char *, XColor []); void drawrectangle(Display *, int, int, int, int, int, Drawable, int, int, Bool, XColor); void drawcircle(Display *, int, int, int, int, Drawable, int, int, Bool, XColor); +void draw_rotate(Display *, int, Drawable, int, int, double); unsigned short textwidth(Display *, XftFont *, char *); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 diff --git a/screen.c b/screen.c index 1715a5be..66559ef2 100644 --- a/screen.c +++ b/screen.c @@ -52,13 +52,19 @@ get_screen_info(Display *disp, int screen, Statusbar *statusbar) if(statusbar) for(i = 0; i < screen_number; i++) - { - if(statusbar->position == BarTop - || statusbar->position == BarBot) - si[i].height -= statusbar->height; - if(statusbar->position == BarTop) + switch(statusbar->position) + { + case BarTop: si[i].y_org += statusbar->height; - } + case BarBot: + si[i].height -= statusbar->height; + break; + case BarLeft: + si[i].x_org += statusbar->height; + case BarRight: + si[i].width -= statusbar->height; + break; + } return si; } diff --git a/statusbar.c b/statusbar.c index a0123ee1..76003971 100644 --- a/statusbar.c +++ b/statusbar.c @@ -20,6 +20,7 @@ */ #include +#include #include "layout.h" #include "statusbar.h" @@ -46,7 +47,7 @@ isoccupied(Client **head, unsigned int t, int screen) } void -drawstatusbar(awesome_config * awesomeconf) +drawstatusbar(awesome_config *awesomeconf) { int z, i, x = 0, y = 0, w; Client *sel = get_current_tag(awesomeconf->tags, awesomeconf->ntags)->client_sel; @@ -157,9 +158,22 @@ drawstatusbar(awesome_config * awesomeconf) awesomeconf->font, NULL, awesomeconf->colors_normal); } - XCopyArea(awesomeconf->display, awesomeconf->statusbar.drawable, - awesomeconf->statusbar.window, DefaultGC(awesomeconf->display, awesomeconf->phys_screen), 0, 0, - awesomeconf->statusbar.width, awesomeconf->statusbar.height, 0, 0); + if(awesomeconf->statusbar.position == BarRight + || awesomeconf->statusbar.position == BarLeft) + { + draw_rotate(awesomeconf->display, awesomeconf->phys_screen, + awesomeconf->statusbar.drawable, awesomeconf->statusbar.width, + awesomeconf->statusbar.height, M_PI * 1.5); + XCopyArea(awesomeconf->display, awesomeconf->statusbar.drawable, + awesomeconf->statusbar.window, + DefaultGC(awesomeconf->display, awesomeconf->phys_screen), 0, 0, + awesomeconf->statusbar.height, awesomeconf->statusbar.width, 0, 0); + } + else + XCopyArea(awesomeconf->display, awesomeconf->statusbar.drawable, + awesomeconf->statusbar.window, + DefaultGC(awesomeconf->display, awesomeconf->phys_screen), 0, 0, + awesomeconf->statusbar.width, awesomeconf->statusbar.height, 0, 0); XSync(awesomeconf->display, False); } @@ -170,8 +184,13 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, Xf int i, phys_screen = get_phys_screen(disp, screen); ScreenInfo *si = get_screen_info(disp, screen, NULL); - statusbar->width = si[screen].width; statusbar->height = font->height * 1.5; + + if(statusbar->position == BarRight || statusbar->position == BarLeft) + statusbar->width = si[screen].height; + else + statusbar->width = si[screen].width; + p_delete(&si); statusbar->screen = screen; @@ -182,20 +201,37 @@ initstatusbar(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, Xf wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ButtonPressMask | ExposureMask; - statusbar->window = XCreateWindow(disp, RootWindow(disp, phys_screen), 0, 0, - statusbar->width, - statusbar->height, - 0, DefaultDepth(disp, phys_screen), CopyFromParent, - DefaultVisual(disp, phys_screen), - CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); + if(statusbar->dposition == BarRight || statusbar->dposition == BarLeft) + { + statusbar->window = XCreateWindow(disp, RootWindow(disp, phys_screen), 0, 0, + statusbar->height, + statusbar->width, + 0, DefaultDepth(disp, phys_screen), CopyFromParent, + DefaultVisual(disp, phys_screen), + CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); + statusbar->drawable = XCreatePixmap(disp, + RootWindow(disp, phys_screen), + statusbar->width, + statusbar->width, + DefaultDepth(disp, phys_screen)); + } + else + { + statusbar->window = XCreateWindow(disp, RootWindow(disp, phys_screen), 0, 0, + statusbar->width, + statusbar->height, + 0, DefaultDepth(disp, phys_screen), CopyFromParent, + DefaultVisual(disp, phys_screen), + CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); + statusbar->drawable = XCreatePixmap(disp, + RootWindow(disp, phys_screen), + statusbar->width, + statusbar->height, + DefaultDepth(disp, phys_screen)); + } XDefineCursor(disp, statusbar->window, cursor); updatebarpos(disp, *statusbar); XMapRaised(disp, statusbar->window); - statusbar->drawable = XCreatePixmap(disp, - RootWindow(disp, phys_screen), - statusbar->width, - statusbar->height, - DefaultDepth(disp, phys_screen)); for(i = 0; i < nlayouts; i++) statusbar->txtlayoutwidth = MAX(statusbar->txtlayoutwidth, @@ -213,6 +249,9 @@ updatebarpos(Display *disp, Statusbar statusbar) default: XMoveWindow(disp, statusbar.window, si[statusbar.screen].x_org, si[statusbar.screen].y_org); break; + case BarRight: + XMoveWindow(disp, statusbar.window, si[statusbar.screen].width - statusbar.width, si[statusbar.screen].y_org); + break; case BarBot: XMoveWindow(disp, statusbar.window, si[statusbar.screen].x_org, si[statusbar.screen].height - statusbar.height); break;