play with vertical panel

git-svn-id: http://tint2.googlecode.com/svn/trunk@121 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
lorthiois@bbsoft.fr 2009-06-21 22:01:31 +00:00
parent c7ba119ff2
commit 6f9a16de47
7 changed files with 145 additions and 69 deletions

View file

@ -1,3 +1,6 @@
2009-06-21
- play with some code for vertical panel
2009-06-20 2009-06-20
- remove flickering on systray - remove flickering on systray

View file

@ -1,6 +1,6 @@
# -*- Autoconf -*- # -*- Autoconf -*-
# Process this file with autoconf to produce a configure script. # 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 LT_INIT
AM_INIT_AUTOMAKE AM_INIT_AUTOMAKE

View file

@ -109,6 +109,8 @@ void init_battery()
battery->area.panel = panel; battery->area.panel = panel;
battery->area._draw_foreground = draw_battery; battery->area._draw_foreground = draw_battery;
battery->area._resize = resize_battery; battery->area._resize = resize_battery;
battery->area.resize = 1;
battery->area.redraw = 1;
if((fp = fopen(path_energy_now, "r")) == NULL) { if((fp = fopen(path_energy_now, "r")) == NULL) {
fprintf(stderr, "ERROR: battery applet can't open energy_now\n"); fprintf(stderr, "ERROR: battery applet can't open energy_now\n");
@ -135,20 +137,27 @@ void init_battery()
} }
fclose(fp); 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); update_battery(&battery_state);
snprintf(buf_bat_percentage, sizeof(buf_bat_percentage), "%d%%", battery_state.percentage); 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); 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)); 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)); 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->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; 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; new_percentage = (energy_now*100)/energy_full;
if(battery_low_status != 0 && battery_low_status == new_percentage && battery_state.percentage > new_percentage) { if(battery_low_status != 0 && battery_low_status == new_percentage && battery_state.percentage > new_percentage) {
printf("battery low, executing: %s\n", battery_low_cmd); //printf("battery low, executing: %s\n", battery_low_cmd);
if(battery_low_cmd) system(battery_low_cmd); if (battery_low_cmd) system(battery_low_cmd);
} }
battery_state.percentage = new_percentage; 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_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); 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_surface_t *cs;
cairo_t *c; cairo_t *c;

View file

@ -71,26 +71,38 @@ void init_clock()
panel = &panel1[i]; panel = &panel1[i];
clock = &panel->clock; clock = &panel->clock;
if (!clock->area.on_screen) continue;
clock->area.parent = panel; clock->area.parent = panel;
clock->area.panel = panel; clock->area.panel = panel;
clock->area._draw_foreground = draw_clock; clock->area._draw_foreground = draw_clock;
clock->area._resize = resize_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.resize = 1;
clock->area.redraw = 1; clock->area.redraw = 1;
strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); 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));
get_text_size(time1_font_desc, &time_height_ink, &time_height, panel->area.height, buf_time, strlen(buf_time)); 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 (time2_format) { 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));
}
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)); 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); 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; Clock *clock = obj;
PangoLayout *layout; PangoLayout *layout;
//printf(" draw_clock : %s en (%d, %d)\n", buf_time, clock->area.posx, clock->area.width);
layout = pango_cairo_create_layout (c); layout = pango_cairo_create_layout (c);
// draw layout // draw layout
@ -141,13 +152,15 @@ void resize_clock (void *obj)
PangoLayout *layout; PangoLayout *layout;
int time_width, date_width, new_width; int time_width, date_width, new_width;
time_width = date_width = 0;
clock->area.redraw = 1; clock->area.redraw = 1;
time_width = date_width = 0;
strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec));
if (time2_format) if (time2_format)
strftime(buf_date, sizeof(buf_date), time2_format, localtime(&time_clock.tv_sec)); 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"); //printf(" resize_clock\n");
cairo_surface_t *cs; cairo_surface_t *cs;
cairo_t *c; cairo_t *c;
@ -159,20 +172,20 @@ void resize_clock (void *obj)
layout = pango_cairo_create_layout (c); layout = pango_cairo_create_layout (c);
// check width // check width
pango_layout_set_font_description (layout, time1_font_desc); pango_layout_set_font_description (layout, time1_font_desc);
pango_layout_set_indent(layout, 0); pango_layout_set_indent(layout, 0);
pango_layout_set_text (layout, buf_time, strlen(buf_time)); pango_layout_set_text (layout, buf_time, strlen(buf_time));
pango_layout_get_pixel_size (layout, &time_width, NULL); pango_layout_get_pixel_size (layout, &time_width, NULL);
if (time2_format) { if (time2_format) {
pango_layout_set_font_description (layout, time2_font_desc); pango_layout_set_font_description (layout, time2_font_desc);
pango_layout_set_indent(layout, 0); pango_layout_set_indent(layout, 0);
pango_layout_set_text (layout, buf_date, strlen(buf_date)); pango_layout_set_text (layout, buf_date, strlen(buf_date));
pango_layout_get_pixel_size (layout, &date_width, NULL); pango_layout_get_pixel_size (layout, &date_width, NULL);
} }
if (time_width > date_width) new_width = time_width; if (time_width > date_width) new_width = time_width;
else new_width = date_width; else new_width = date_width;
new_width += (2*clock->area.paddingxlr) + (2*clock->area.pix.border.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)) { if (new_width > clock->area.width || new_width < (clock->area.width-6)) {
Panel *panel = ((Area*)obj)->panel; Panel *panel = ((Area*)obj)->panel;
@ -180,8 +193,8 @@ void resize_clock (void *obj)
// resize clock // resize clock
// we try to limit the number of resize // we try to limit the number of resize
// printf("clock_width %d, new_width %d\n", clock->area.width, new_width); // printf("clock_width %d, new_width %d\n", clock->area.width, new_width);
clock->area.width = new_width + 1; 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.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.pix.border.width;
// resize other objects on panel // resize other objects on panel
panel->area.resize = 1; panel->area.resize = 1;

View file

@ -298,9 +298,12 @@ void add_entry (char *key, char *value)
else if (strcmp (key, "panel_position") == 0) { else if (strcmp (key, "panel_position") == 0) {
extract_values(value, &value1, &value2, &value3); extract_values(value, &value1, &value2, &value3);
if (strcmp (value1, "top") == 0) panel_position = TOP; 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 { else {
if (strcmp (value2, "left") == 0) panel_position |= LEFT; if (strcmp (value2, "left") == 0) panel_position |= LEFT;
else { else {
@ -308,6 +311,11 @@ void add_entry (char *key, char *value)
else panel_position |= CENTER; 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) else if (strcmp (key, "font_shadow") == 0)
panel_config->g_task.font_shadow = atoi (value); panel_config->g_task.font_shadow = atoi (value);

View file

@ -42,6 +42,7 @@ int mouse_scroll_down;
int panel_mode; int panel_mode;
int wm_menu; int wm_menu;
int panel_position; int panel_position;
int panel_horizontal;
int panel_refresh; int panel_refresh;
Task *task_active; Task *task_active;
@ -83,22 +84,37 @@ void init_panel()
if (systray.area.on_screen && i == 0) if (systray.area.on_screen && i == 0)
p->area.list = g_slist_append(p->area.list, &systray); 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 // full width mode
if (!p->area.width) if (!p->initial_width) {
p->area.width = server.monitor[p->monitor].width; p->initial_width = 100;
p->pourcentx = 1;
}
if (p->area.pix.border.rounded > p->area.height/2) // detect panel size
p->area.pix.border.rounded = p->area.height/2; 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 */ /* panel position determined here */
if (panel_position & LEFT) { 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; p->posx = server.monitor[p->monitor].x + server.monitor[p->monitor].width - p->area.width - p->marginx;
} }
else { 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) { if (panel_position & TOP) {
p->posy = server.monitor[p->monitor].y + p->marginy; p->posy = server.monitor[p->monitor].y + p->marginy;
} }
else { 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 // Catch some events
XSetWindowAttributes att = { ParentRelative, 0L, 0, 0L, 0, 0, Always, 0L, 0L, False, ExposureMask|ButtonPressMask|ButtonReleaseMask, NoEventMask, False, 0, 0 }; 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 // Reserved space
long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; long struts [12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
if (panel_position & TOP) { if (panel_horizontal) {
struts[2] = p->area.height + p->marginy; if (panel_position & TOP) {
struts[8] = p->posx; struts[2] = p->area.height + p->marginy;
// p->area.width - 1 allowed full screen on monitor 2 struts[8] = p->posx;
struts[9] = p->posx + p->area.width - 1; // 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; else {
struts[10] = p->posx; struts[3] = p->area.height + p->marginy;
// p->area.width - 1 allowed full screen on monitor 2 struts[10] = p->posx;
struts[11] = p->posx + p->area.width - 1; // 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. // 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, 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); XChangeProperty (server.dsp, p->main_win, server.atom._NET_WM_STRUT_PARTIAL, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12);

View file

@ -41,6 +41,7 @@ extern int wm_menu;
//panel position //panel position
enum { LEFT=0x01, RIGHT=0x02, CENTER=0X04, TOP=0X08, BOTTOM=0x10 }; enum { LEFT=0x01, RIGHT=0x02, CENTER=0X04, TOP=0X08, BOTTOM=0x10 };
extern int panel_position; extern int panel_position;
extern int panel_horizontal;
extern int panel_refresh; extern int panel_refresh;