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
- remove flickering on systray

View 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

View 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,7 +226,7 @@ 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);
//printf("battery low, executing: %s\n", battery_low_cmd);
if (battery_low_cmd) system(battery_low_cmd);
}
@ -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;

View 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)
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));
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));
}
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;

View 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);

View 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,7 +84,14 @@ void init_panel()
if (systray.area.on_screen && i == 0)
p->area.list = g_slist_append(p->area.list, &systray);
// full width mode
if (!p->initial_width) {
p->initial_width = 100;
p->pourcentx = 1;
}
// detect panel size
if (panel_horizontal) {
if (p->pourcentx)
p->area.width = (float)server.monitor[p->monitor].width * p->initial_width / 100;
else
@ -92,13 +100,21 @@ void init_panel()
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->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 {
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 {
if (panel_position & BOTTOM) {
p->posy = server.monitor[p->monitor].y + server.monitor[p->monitor].height - p->area.height - p->marginy;
}
//printf("posx %d, posy %d, width %d, height %d\n", p->posx, p->posy, p->area.width, p->area.height);
else {
p->posy = server.monitor[p->monitor].y + ((server.monitor[p->monitor].height - p->area.height) / 2);
}
}
// 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,6 +285,7 @@ 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_horizontal) {
if (panel_position & TOP) {
struts[2] = p->area.height + p->marginy;
struts[8] = p->posx;
@ -273,6 +298,21 @@ void set_panel_properties(Panel *p)
// 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);

View 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;