From: Thierry Lorthiois Date: Sun, 21 Jun 2009 22:01:31 +0000 (+0000) Subject: play with vertical panel X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=ddd6fcc40dbe9d4257ff904d5e156b7f612dedc4;p=chaz%2Ftint2 play with vertical panel --- diff --git a/ChangeLog b/ChangeLog index 17d03af..ae41e69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2009-06-21 +- play with some code for vertical panel + 2009-06-20 - remove flickering on systray diff --git a/configure.ac b/configure.ac index 4e584cc..31408b0 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_INIT([tint2], [0.7_beta2], [http://code.google.com/p/tint2/issues]) +AC_INIT([tint2], [0.7_beta3], [http://code.google.com/p/tint2/issues]) LT_INIT AM_INIT_AUTOMAKE diff --git a/src/battery/battery.c b/src/battery/battery.c index d1b380f..4dcb99a 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -109,6 +109,8 @@ void init_battery() battery->area.panel = panel; battery->area._draw_foreground = draw_battery; battery->area._resize = resize_battery; + battery->area.resize = 1; + battery->area.redraw = 1; if((fp = fopen(path_energy_now, "r")) == NULL) { fprintf(stderr, "ERROR: battery applet can't open energy_now\n"); @@ -135,20 +137,27 @@ void init_battery() } fclose(fp); - battery->area.posy = panel->area.pix.border.width + panel->area.paddingy; - battery->area.height = panel->area.height - (2 * battery->area.posy); - battery->area.resize = 1; - battery->area.redraw = 1; - update_battery(&battery_state); snprintf(buf_bat_percentage, sizeof(buf_bat_percentage), "%d%%", battery_state.percentage); snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes); get_text_size(bat1_font_desc, &bat_percentage_height_ink, &bat_percentage_height, panel->area.height, buf_bat_percentage, strlen(buf_bat_percentage)); - battery->bat1_posy = (battery->area.height - bat_percentage_height) / 2; - get_text_size(bat2_font_desc, &bat_time_height_ink, &bat_time_height, panel->area.height, buf_bat_time, strlen(buf_bat_time)); + if (panel_horizontal) { + // panel horizonal => fixed height and posy + battery->area.posy = panel->area.pix.border.width + panel->area.paddingy; + battery->area.height = panel->area.height - (2 * battery->area.posy); + } + else { + // panel vertical => fixed width, height, posy and posx + battery->area.posy = panel->clock.area.posy + panel->clock.area.height + panel->area.paddingx; + battery->area.height = (2 * battery->area.paddingxlr) + (bat_time_height + bat_percentage_height); + battery->area.posx = panel->area.pix.border.width + panel->area.paddingy; + battery->area.width = panel->area.width - (2 * panel->area.pix.border.width) - (2 * panel->area.paddingy); + } + + battery->bat1_posy = (battery->area.height - bat_percentage_height) / 2; battery->bat1_posy -= ((bat_time_height_ink + 2) / 2); battery->bat2_posy = battery->bat1_posy + bat_percentage_height + 2 - (bat_percentage_height - bat_percentage_height_ink)/2 - (bat_time_height - bat_time_height_ink)/2; } @@ -217,8 +226,8 @@ void update_battery() { new_percentage = (energy_now*100)/energy_full; if(battery_low_status != 0 && battery_low_status == new_percentage && battery_state.percentage > new_percentage) { - printf("battery low, executing: %s\n", battery_low_cmd); - if(battery_low_cmd) system(battery_low_cmd); + //printf("battery low, executing: %s\n", battery_low_cmd); + if (battery_low_cmd) system(battery_low_cmd); } battery_state.percentage = new_percentage; @@ -268,6 +277,8 @@ void resize_battery(void *obj) snprintf(buf_bat_percentage, sizeof(buf_bat_percentage), "%d%%", battery_state.percentage); snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes); + // vertical panel doen't adjust width + if (!panel_horizontal) return; cairo_surface_t *cs; cairo_t *c; diff --git a/src/clock/clock.c b/src/clock/clock.c index 2e54d10..a29eae5 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -71,26 +71,38 @@ void init_clock() panel = &panel1[i]; clock = &panel->clock; + if (!clock->area.on_screen) continue; + clock->area.parent = panel; clock->area.panel = panel; clock->area._draw_foreground = draw_clock; clock->area._resize = resize_clock; - - if (!clock->area.on_screen) continue; - - clock->area.posy = panel->area.pix.border.width + panel->area.paddingy; - clock->area.height = panel->area.height - (2 * clock->area.posy); clock->area.resize = 1; clock->area.redraw = 1; strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); - if (time2_format) + get_text_size(time1_font_desc, &time_height_ink, &time_height, panel->area.height, buf_time, strlen(buf_time)); + if (time2_format) { strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); + get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date)); + } - get_text_size(time1_font_desc, &time_height_ink, &time_height, panel->area.height, buf_time, strlen(buf_time)); - clock->time1_posy = (clock->area.height - time_height) / 2; + if (panel_horizontal) { + // panel horizonal => fixed height and posy + clock->area.posy = panel->area.pix.border.width + panel->area.paddingy; + clock->area.height = panel->area.height - (2 * clock->area.posy); + } + else { + // panel vertical => fixed width, height, posy and posx + clock->area.posy = panel->area.pix.border.width + panel->area.paddingxlr; + clock->area.height = (2 * clock->area.paddingxlr) + (time_height + date_height); + clock->area.posx = panel->area.pix.border.width + panel->area.paddingy; + clock->area.width = panel->area.width - (2 * panel->area.pix.border.width) - (2 * panel->area.paddingy); + } + clock->time1_posy = (clock->area.height - time_height) / 2; if (time2_format) { + strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); get_text_size(time2_font_desc, &date_height_ink, &date_height, panel->area.height, buf_date, strlen(buf_date)); clock->time1_posy -= ((date_height_ink + 2) / 2); @@ -105,7 +117,6 @@ void draw_clock (void *obj, cairo_t *c, int active) Clock *clock = obj; PangoLayout *layout; - //printf(" draw_clock : %s en (%d, %d)\n", buf_time, clock->area.posx, clock->area.width); layout = pango_cairo_create_layout (c); // draw layout @@ -141,13 +152,15 @@ void resize_clock (void *obj) PangoLayout *layout; int time_width, date_width, new_width; - time_width = date_width = 0; clock->area.redraw = 1; - + time_width = date_width = 0; strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); if (time2_format) strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); + // vertical panel doen't adjust width + if (!panel_horizontal) return; + //printf(" resize_clock\n"); cairo_surface_t *cs; cairo_t *c; @@ -159,20 +172,20 @@ void resize_clock (void *obj) layout = pango_cairo_create_layout (c); // check width - pango_layout_set_font_description (layout, time1_font_desc); - pango_layout_set_indent(layout, 0); - pango_layout_set_text (layout, buf_time, strlen(buf_time)); - pango_layout_get_pixel_size (layout, &time_width, NULL); - if (time2_format) { - pango_layout_set_font_description (layout, time2_font_desc); - pango_layout_set_indent(layout, 0); - pango_layout_set_text (layout, buf_date, strlen(buf_date)); - pango_layout_get_pixel_size (layout, &date_width, NULL); - } + pango_layout_set_font_description (layout, time1_font_desc); + pango_layout_set_indent(layout, 0); + pango_layout_set_text (layout, buf_time, strlen(buf_time)); + pango_layout_get_pixel_size (layout, &time_width, NULL); + if (time2_format) { + pango_layout_set_font_description (layout, time2_font_desc); + pango_layout_set_indent(layout, 0); + pango_layout_set_text (layout, buf_date, strlen(buf_date)); + pango_layout_get_pixel_size (layout, &date_width, NULL); + } - if (time_width > date_width) new_width = time_width; - else new_width = date_width; - new_width += (2*clock->area.paddingxlr) + (2*clock->area.pix.border.width); + if (time_width > date_width) new_width = time_width; + else new_width = date_width; + new_width += (2*clock->area.paddingxlr) + (2*clock->area.pix.border.width); if (new_width > clock->area.width || new_width < (clock->area.width-6)) { Panel *panel = ((Area*)obj)->panel; @@ -180,8 +193,8 @@ void resize_clock (void *obj) // resize clock // we try to limit the number of resize // printf("clock_width %d, new_width %d\n", clock->area.width, new_width); - clock->area.width = new_width + 1; - clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.pix.border.width; + clock->area.width = new_width + 1; + clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.pix.border.width; // resize other objects on panel panel->area.resize = 1; diff --git a/src/config.c b/src/config.c index 9405146..6a74227 100644 --- a/src/config.c +++ b/src/config.c @@ -298,9 +298,12 @@ void add_entry (char *key, char *value) else if (strcmp (key, "panel_position") == 0) { extract_values(value, &value1, &value2, &value3); if (strcmp (value1, "top") == 0) panel_position = TOP; - else panel_position = BOTTOM; + else { + if (strcmp (value1, "bottom") == 0) panel_position = BOTTOM; + else panel_position = CENTER; + } - if (!value2) panel_position = CENTER; + if (!value2) panel_position |= CENTER; else { if (strcmp (value2, "left") == 0) panel_position |= LEFT; else { @@ -308,6 +311,11 @@ void add_entry (char *key, char *value) else panel_position |= CENTER; } } + if (!value3) panel_horizontal = 1; + else { + if (strcmp (value3, "vertical") == 0) panel_horizontal = 0; + else panel_horizontal = 1; + } } else if (strcmp (key, "font_shadow") == 0) panel_config->g_task.font_shadow = atoi (value); diff --git a/src/panel.c b/src/panel.c index 161d902..89ea838 100644 --- a/src/panel.c +++ b/src/panel.c @@ -42,6 +42,7 @@ int mouse_scroll_down; int panel_mode; int wm_menu; int panel_position; +int panel_horizontal; int panel_refresh; Task *task_active; @@ -83,22 +84,37 @@ void init_panel() if (systray.area.on_screen && i == 0) p->area.list = g_slist_append(p->area.list, &systray); - // detect panel size - if (p->pourcentx) - p->area.width = (float)server.monitor[p->monitor].width * p->initial_width / 100; - else - p->area.width = p->initial_width; - if (p->pourcenty) - p->area.height = (float)server.monitor[p->monitor].height * p->initial_height / 100; - else - p->area.height = p->initial_height; - // full width mode - if (!p->area.width) - p->area.width = server.monitor[p->monitor].width; + if (!p->initial_width) { + p->initial_width = 100; + p->pourcentx = 1; + } - if (p->area.pix.border.rounded > p->area.height/2) - p->area.pix.border.rounded = p->area.height/2; + // detect panel size + if (panel_horizontal) { + if (p->pourcentx) + p->area.width = (float)server.monitor[p->monitor].width * p->initial_width / 100; + else + p->area.width = p->initial_width; + if (p->pourcenty) + p->area.height = (float)server.monitor[p->monitor].height * p->initial_height / 100; + else + p->area.height = p->initial_height; + if (p->area.pix.border.rounded > p->area.height/2) + p->area.pix.border.rounded = p->area.height/2; + } + else { + if (p->pourcentx) + p->area.height = (float)server.monitor[p->monitor].height * p->initial_width / 100; + else + p->area.height = p->initial_width; + if (p->pourcenty) + p->area.width = (float)server.monitor[p->monitor].width * p->initial_height / 100; + else + p->area.width = p->initial_height; + if (p->area.pix.border.rounded > p->area.width/2) + p->area.pix.border.rounded = p->area.width/2; + } /* panel position determined here */ if (panel_position & LEFT) { @@ -109,16 +125,24 @@ void init_panel() p->posx = server.monitor[p->monitor].x + server.monitor[p->monitor].width - p->area.width - p->marginx; } else { - p->posx = server.monitor[p->monitor].x + ((server.monitor[p->monitor].width - p->area.width) / 2); + if (panel_horizontal) + p->posx = server.monitor[p->monitor].x + ((server.monitor[p->monitor].width - p->area.width) / 2); + else + p->posx = server.monitor[p->monitor].x + p->marginx; } } if (panel_position & TOP) { p->posy = server.monitor[p->monitor].y + p->marginy; } else { - p->posy = server.monitor[p->monitor].y + server.monitor[p->monitor].height - p->area.height - p->marginy; + if (panel_position & BOTTOM) { + p->posy = server.monitor[p->monitor].y + server.monitor[p->monitor].height - p->area.height - p->marginy; + } + else { + p->posy = server.monitor[p->monitor].y + ((server.monitor[p->monitor].height - p->area.height) / 2); + } } - //printf("posx %d, posy %d, width %d, height %d\n", p->posx, p->posy, p->area.width, p->area.height); + // printf("panel : posx %d, posy %d, width %d, height %d\n", p->posx, p->posy, p->area.width, p->area.height); // Catch some events XSetWindowAttributes att = { ParentRelative, 0L, 0, 0L, 0, 0, Always, 0L, 0L, False, ExposureMask|ButtonPressMask|ButtonReleaseMask, NoEventMask, False, 0, 0 }; @@ -261,18 +285,34 @@ void set_panel_properties(Panel *p) // Reserved space long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - if (panel_position & TOP) { - struts[2] = p->area.height + p->marginy; - struts[8] = p->posx; - // p->area.width - 1 allowed full screen on monitor 2 - struts[9] = p->posx + p->area.width - 1; - } - else { - struts[3] = p->area.height + p->marginy; - struts[10] = p->posx; - // p->area.width - 1 allowed full screen on monitor 2 - struts[11] = p->posx + p->area.width - 1; - } + if (panel_horizontal) { + if (panel_position & TOP) { + struts[2] = p->area.height + p->marginy; + struts[8] = p->posx; + // p->area.width - 1 allowed full screen on monitor 2 + struts[9] = p->posx + p->area.width - 1; + } + else { + struts[3] = p->area.height + p->marginy; + struts[10] = p->posx; + // p->area.width - 1 allowed full screen on monitor 2 + struts[11] = p->posx + p->area.width - 1; + } + } + else { + if (panel_position & LEFT) { + struts[0] = p->area.width + p->marginx; + struts[4] = p->posy; + // p->area.width - 1 allowed full screen on monitor 2 + struts[5] = p->posy + p->area.height - 1; + } + else { + struts[1] = p->area.width + p->marginx; + struts[6] = p->posy; + // p->area.width - 1 allowed full screen on monitor 2 + struts[7] = p->posy + p->area.height - 1; + } + } // Old specification : fluxbox need _NET_WM_STRUT. XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4); XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12); diff --git a/src/panel.h b/src/panel.h index a8247a9..b9915e6 100644 --- a/src/panel.h +++ b/src/panel.h @@ -41,6 +41,7 @@ extern int wm_menu; //panel position enum { LEFT=0x01, RIGHT=0x02, CENTER=0X04, TOP=0X08, BOTTOM=0x10 }; extern int panel_position; +extern int panel_horizontal; extern int panel_refresh;