]> Dogcows Code - chaz/tint2/commitdiff
play with vertical panel
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Sun, 21 Jun 2009 22:01:31 +0000 (22:01 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Sun, 21 Jun 2009 22:01:31 +0000 (22:01 +0000)
ChangeLog
configure.ac
src/battery/battery.c
src/clock/clock.c
src/config.c
src/panel.c
src/panel.h

index 17d03afdb58bba3fb8fec46f3466ac4b39582f1a..ae41e69178232fa35b1692fd748fea90ce409085 100644 (file)
--- 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
 
index 4e584cc1b7f703653a7ee7ac7c7969a1874c18d4..31408b0da41235ee858c9b26139da89ca75cbb0d 100644 (file)
@@ -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
index d1b380fdaf54e9803ef8b94d3ae5935145fc01a7..4dcb99a47cffab9755daa5ea7b29599fb69f717d 100644 (file)
@@ -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;
index 2e54d10c0751cc7242af11f31f1c690ef3bcdd7a..a29eae545f465cd08c60b8a973b1d13b72c4ed75 100644 (file)
@@ -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;
index 9405146c27cd504abc60c42f3cd6191664ed2d99..6a7422790b563990f72a8e232b4698a620c3d390 100644 (file)
@@ -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);
index 161d9023966182d6e0b934f9d17bd46986ae40b9..89ea8382be99ecc51b9540921b757e83cee87511 100644 (file)
@@ -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);
index a8247a91af375c6803a1d05393f099a633bc00a0..b9915e66a3d1d98c287805547a4c0d77275009a6 100644 (file)
@@ -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;
 
This page took 0.03734 seconds and 4 git commands to generate.