all repos — tint2 @ d94e2a179060148e4024d3bbe280fade75f2568b

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

desktop name: first step

git-svn-id: http://tint2.googlecode.com/svn/trunk@596 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
thilor77 thilor77@121b4492-b84c-0410-8b4c-0d4edfb3f3cc
commit

d94e2a179060148e4024d3bbe280fade75f2568b

parent

a7a2ae337a962351900e957e723330fc3fe3d857

M src/config.csrc/config.c

@@ -467,12 +467,23 @@ else if (strcmp (key, "taskbar_name") == 0) {

taskbarname_enabled = atoi (value); } else if (strcmp (key, "taskbar_name_background_id") == 0) { + int id = atoi (value); + id = (id < backgrounds->len && id >= 0) ? id : 0; + panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id); } else if (strcmp (key, "taskbar_name_active_background_id") == 0) { + int id = atoi (value); + id = (id < backgrounds->len && id >= 0) ? id : 0; + panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id); } else if (strcmp (key, "taskbar_name_font") == 0) { + taskbarname_font_desc = pango_font_description_from_string (value); } else if (strcmp (key, "taskbar_name_font_color") == 0) { + extract_values(value, &value1, &value2, &value3); + get_color (value1, taskbarname_font.color); + if (value2) taskbarname_font.alpha = (atoi (value2) / 100.0); + else taskbarname_font.alpha = 0.5; } else if (strcmp (key, "taskbar_name_active_font_color") == 0) { }
M src/panel.csrc/panel.c

@@ -169,9 +169,6 @@ p->area.on_screen = 1;

p->area.resize = 1; p->area.size_mode = SIZE_BY_LAYOUT; p->area._resize = resize_panel; - p->g_taskbar.area.parent = p; - p->g_taskbar.area.panel = p; - p->g_task.area.panel = p; init_panel_size_and_position(p); // add childs according to panel_items for (k=0 ; k < strlen(panel_items_order) ; k++) {

@@ -540,7 +537,9 @@ if (tskbar->state_pix[k]) XFreePixmap(server.dsp, tskbar->state_pix[k]);

tskbar->state_pix[k] = 0; } tskbar->area.pix = 0; - for (l0 = tskbar->area.list; l0 ; l0 = l0->next) { + l0 = tskbar->area.list; + if (taskbarname_enabled) l0 = l0->next; + for (; l0 ; l0 = l0->next) { set_task_redraw((Task *)l0->data); } }

@@ -590,7 +589,9 @@

if ( (tskbar = click_taskbar(panel, x, y)) ) { if (panel_horizontal) { Task *tsk; - for (l0 = tskbar->area.list; l0 ; l0 = l0->next) { + l0 = tskbar->area.list; + if (taskbarname_enabled) l0 = l0->next; + for (; l0 ; l0 = l0->next) { tsk = l0->data; if (tsk->area.on_screen && x >= tsk->area.posx && x <= (tsk->area.posx + tsk->area.width)) { return tsk;

@@ -599,7 +600,9 @@ }

} else { Task *tsk; - for (l0 = tskbar->area.list; l0 ; l0 = l0->next) { + l0 = tskbar->area.list; + if (taskbarname_enabled) l0 = l0->next; + for (; l0 ; l0 = l0->next) { tsk = l0->data; if (tsk->area.on_screen && y >= tsk->area.posy && y <= (tsk->area.posy + tsk->area.height)) { return tsk;
M src/taskbar/task.csrc/taskbar/task.c

@@ -414,7 +414,9 @@ GSList *l0;

Task *tsk1; Taskbar* tskbar = tsk->area.parent; - for (l0 = tskbar->area.list; l0 ; l0 = l0->next) { + l0 = tskbar->area.list; + if (taskbarname_enabled) l0 = l0->next; + for (; l0 ; l0 = l0->next) { tsk1 = l0->data; if (tsk1 == tsk) { if (l0->next == 0) l0 = tskbar->area.list;

@@ -436,7 +438,9 @@ Task *tsk1, *tsk2;

Taskbar* tskbar = tsk->area.parent; tsk2 = 0; - for (l0 = tskbar->area.list; l0 ; l0 = l0->next) { + l0 = tskbar->area.list; + if (taskbarname_enabled) l0 = l0->next; + for (; l0 ; l0 = l0->next) { tsk1 = l0->data; if (tsk1 == tsk) { if (l0 == tskbar->area.list) {
M src/taskbar/taskbar.csrc/taskbar/taskbar.c

@@ -54,6 +54,7 @@ win_to_task_table = 0;

urgent_timeout = 0; urgent_list = 0; taskbar_enabled = 0; + default_taskbarname(); } void cleanup_taskbar()

@@ -62,6 +63,7 @@ Panel *panel;

Taskbar *tskbar; int i, j, k; + cleanup_taskbarname(); if (win_to_task_table) g_hash_table_foreach(win_to_task_table, taskbar_remove_task, 0); for (i=0 ; i < nb_panel ; i++) { panel = &panel1[i];

@@ -106,30 +108,50 @@ if (panel->g_taskbar.background[TASKBAR_NORMAL] == 0) {

panel->g_taskbar.background[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, 0); panel->g_taskbar.background[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, 0); } + if (panel->g_taskbar.background_name[TASKBAR_NORMAL] == 0) { + panel->g_taskbar.background_name[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, 0); + panel->g_taskbar.background_name[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, 0); + } if (panel->g_task.area.bg == 0) panel->g_task.area.bg = &g_array_index(backgrounds, Background, 0); + // taskbar name + panel->g_taskbar.area_name.panel = panel; + panel->g_taskbar.area_name.size_mode = SIZE_BY_CONTENT; + panel->g_taskbar.area_name._resize = resize_taskbarname; + panel->g_taskbar.area_name._draw_foreground = draw_taskbarname; + panel->g_taskbar.area_name._on_change_layout = 0; + panel->g_taskbar.area_name.resize = 1; + panel->g_taskbar.area_name.on_screen = 1; + // taskbar + panel->g_taskbar.area.parent = panel; + panel->g_taskbar.area.panel = panel; panel->g_taskbar.area.size_mode = SIZE_BY_LAYOUT; panel->g_taskbar.area._resize = resize_taskbar; panel->g_taskbar.area._draw_foreground = draw_taskbar; panel->g_taskbar.area._on_change_layout = on_change_taskbar; - panel->g_taskbar.area.redraw = 1; + panel->g_taskbar.area.resize = 1; panel->g_taskbar.area.on_screen = 1; if (panel_horizontal) { panel->g_taskbar.area.posy = panel->area.bg->border.width + panel->area.paddingy; panel->g_taskbar.area.height = panel->area.height - (2 * panel->g_taskbar.area.posy); + panel->g_taskbar.area_name.posy = panel->g_taskbar.area.posy; + panel->g_taskbar.area_name.height = panel->g_taskbar.area.height; } else { panel->g_taskbar.area.posx = panel->area.bg->border.width + panel->area.paddingy; panel->g_taskbar.area.width = panel->area.width - (2 * panel->g_taskbar.area.posx); + panel->g_taskbar.area_name.posx = panel->g_taskbar.area.posx; + panel->g_taskbar.area_name.width = panel->g_taskbar.area.width; } // task + panel->g_task.area.panel = panel; panel->g_task.area.size_mode = SIZE_BY_LAYOUT; panel->g_task.area._draw_foreground = draw_task; panel->g_task.area._on_change_layout = on_change_task; - panel->g_task.area.redraw = 1; + panel->g_task.area.resize = 1; panel->g_task.area.on_screen = 1; if ((panel->g_task.config_asb_mask & (1<<TASK_NORMAL)) == 0) { panel->g_task.alpha[TASK_NORMAL] = 100;

@@ -200,13 +222,24 @@ panel->nb_desktop = server.nb_desktop;

panel->taskbar = calloc(server.nb_desktop, sizeof(Taskbar)); for (j=0 ; j < panel->nb_desktop ; j++) { tskbar = &panel->taskbar[j]; - memcpy(&tskbar->area, &panel->g_taskbar, sizeof(Area)); + memcpy(&tskbar->area, &panel->g_taskbar.area, sizeof(Area)); tskbar->desktop = j; if (j == server.desktop) tskbar->area.bg = panel->g_taskbar.background[TASKBAR_ACTIVE]; else tskbar->area.bg = panel->g_taskbar.background[TASKBAR_NORMAL]; + + if (taskbarname_enabled) { + memcpy(&tskbar->bar_name.area, &panel->g_taskbar.area_name, sizeof(Area)); + tskbar->bar_name.area.parent = tskbar; + if (j == server.desktop) + tskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_ACTIVE]; + else + tskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_NORMAL]; + tskbar->area.list = g_slist_append(tskbar->area.list, &tskbar->bar_name); + } } + init_taskbarname_panel(panel); }

@@ -278,16 +311,16 @@ {

Taskbar *taskbar = (Taskbar*)obj; Panel *panel = (Panel*)taskbar->area.panel; int text_width; - Task *tsk; //printf("resize_taskbar %d %d\n", taskbar->area.posx, taskbar->area.posy); if (panel_horizontal) { resize_by_layout(obj, panel->g_task.maximum_width); text_width = panel->g_task.maximum_width; - if (taskbar->area.list != NULL) { - tsk = taskbar->area.list->data; - text_width = tsk->area.width; + GSList *l = taskbar->area.list; + if (taskbarname_enabled) l = l->next; + if (l != NULL) { + text_width = ((Task *)l->data)->area.width; } taskbar->text_width = text_width - panel->g_task.text_posx - panel->g_task.area.bg->border.width - panel->g_task.area.paddingx; }

@@ -329,8 +362,9 @@ if (tskbar->area.on_screen == 1) {

if (tskbar->state_pix[state] == 0) tskbar->area.redraw = 1; if (panel_mode == MULTI_DESKTOP && panel1[0].g_taskbar.background[TASKBAR_NORMAL] != panel1[0].g_taskbar.background[TASKBAR_ACTIVE]) { - GSList *l; - for (l = tskbar->area.list ; l ; l = l->next) + GSList *l = tskbar->area.list; + if (taskbarname_enabled) l = l->next; + for ( ; l ; l = l->next) set_task_redraw(l->data); } }
M src/taskbar/taskbar.hsrc/taskbar/taskbar.h

@@ -9,6 +9,7 @@ #ifndef TASKBAR_H

#define TASKBAR_H #include "task.h" +#include "taskbarname.h" enum { TASKBAR_NORMAL, TASKBAR_ACTIVE, TASKBAR_STATE_COUNT }; extern GHashTable* win_to_task_table;

@@ -16,6 +17,16 @@ extern Task *task_active;

extern Task *task_drag; extern int taskbar_enabled; + +typedef struct { + // always start with area + Area area; + Pixmap state_pix[TASKBAR_STATE_COUNT]; + + char *name; + int name_posy; +} Taskbarname; + // tint2 use one taskbar per desktop. typedef struct { // always start with area

@@ -24,15 +35,18 @@

int desktop; Pixmap state_pix[TASKBAR_STATE_COUNT]; + Taskbarname bar_name; + // task parameters int text_width; } Taskbar; - typedef struct { //always start with area Area area; + Area area_name; Background* background[TASKBAR_STATE_COUNT]; + Background* background_name[TASKBAR_STATE_COUNT]; } Global_taskbar;
M src/taskbar/taskbarname.csrc/taskbar/taskbarname.c

@@ -26,57 +26,129 @@ #include <string.h>

#include <glib.h> #include <Imlib2.h> -#include "taskbarname.h" #include "window.h" #include "panel.h" - +#include "taskbar.h" +#include "server.h" +#include "taskbarname.h" int taskbarname_enabled; +PangoFontDescription *taskbarname_font_desc; +Color taskbarname_font; void default_taskbarname() { taskbarname_enabled = 0; + taskbarname_font_desc = 0; } + +void init_taskbarname_panel(void *p) +{ + Panel *panel =(Panel*)p; + int j; + + if (!taskbarname_enabled || !taskbar_enabled) return; + + for (j=0 ; j < panel->nb_desktop ; j++) { + panel->taskbar[j].bar_name.name = g_strdup_printf("%d", j+1); + } +} + + void cleanup_taskbarname() { + int i, j, k; Panel *panel; Taskbar *tskbar; - int i, j; for (i=0 ; i < nb_panel ; i++) { panel = &panel1[i]; + for (j=0 ; j < panel->nb_desktop ; j++) { + tskbar = &panel->taskbar[j]; + if (taskbarname_font_desc) pango_font_description_free(taskbarname_font_desc); + if (tskbar->bar_name.name) g_free(tskbar->bar_name.name); + free_area (&tskbar->bar_name.area); + for (k=0; k<TASKBAR_STATE_COUNT; ++k) { + if (tskbar->bar_name.state_pix[k]) XFreePixmap(server.dsp, tskbar->bar_name.state_pix[k]); + } + } } } -void init_taskbarname() +void draw_taskbarname (void *obj, cairo_t *c) { -} - + Taskbarname *taskbar_name = obj; + PangoLayout *layout; -void init_taskbarname_panel(void *p) -{ - Panel *panel =(Panel*)p; - - if (!taskbarname_enabled) return; + layout = pango_cairo_create_layout (c); -} + // draw layout + pango_layout_set_font_description (layout, taskbarname_font_desc); + pango_layout_set_width (layout, taskbar_name->area.width * PANGO_SCALE); + pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); + pango_layout_set_text (layout, taskbar_name->name, strlen(taskbar_name->name)); + cairo_set_source_rgba (c, taskbarname_font.color[0], taskbarname_font.color[1], taskbarname_font.color[2], taskbarname_font.alpha); -void draw_taskbarname (void *obj, cairo_t *c) -{ + pango_cairo_update_layout (c, layout); + cairo_move_to (c, 0, 2); + pango_cairo_show_layout (c, layout); + g_object_unref (layout); + printf("draw_taskbarname %s ******************************\n", taskbar_name->name); } int resize_taskbarname(void *obj) { - Taskbar *taskbar = (Taskbar*)obj; - Panel *panel = (Panel*)taskbar->area.panel; + Taskbarname *taskbar_name = (Taskbar*)obj; + Panel *panel = taskbar_name->area.panel; + int time_height, time_width, ret = 0; + + taskbar_name->area.redraw = 1; + /* + strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone)); + get_text_size2(time1_font_desc, &time_height_ink, &time_height, &time_width, panel->area.height, panel->area.width, buf_time, strlen(buf_time)); + if (time2_format) { + strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone)); + get_text_size2(time2_font_desc, &date_height_ink, &date_height, &date_width, panel->area.height, panel->area.width, buf_date, strlen(buf_date)); + } + + if (panel_horizontal) { + int new_size = (time_width > date_width) ? time_width : date_width; + new_size += (2*clock->area.paddingxlr) + (2*clock->area.bg->border.width); + if (new_size > clock->area.width || new_size < (clock->area.width-6)) { + // we try to limit the number of resize + clock->area.width = new_size + 1; + clock->time1_posy = (clock->area.height - time_height) / 2; + if (time2_format) { + clock->time1_posy -= ((date_height_ink + 2) / 2); + clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2; + } + ret = 1; + } + } + else { + int new_size = time_height + date_height + (2 * (clock->area.paddingxlr + clock->area.bg->border.width)); + if (new_size != clock->area.height) { + // we try to limit the number of resize + clock->area.height = new_size; + clock->time1_posy = (clock->area.height - time_height) / 2; + if (time2_format) { + clock->time1_posy -= ((date_height_ink + 2) / 2); + clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2; + } + ret = 1; + } + } + return ret; +*/ - return 0; + taskbar_name->area.width = 10; + return 1; }
M src/taskbar/taskbarname.hsrc/taskbar/taskbarname.h

@@ -1,33 +1,20 @@

/************************************************************************** * Copyright (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr) -* -* taskbarname -* **************************************************************************/ #ifndef TASKBARNAME_H #define TASKBARNAME_H + +#include "common.h" #include "area.h" - extern int taskbarname_enabled; +extern PangoFontDescription *taskbarname_font_desc; +extern Color taskbarname_font; -typedef struct { - // always start with area - Area area; - - int desktop; - -} Taskbarname; - - -// default global data void default_taskbarname(); - -// freed memory void cleanup_taskbarname(); -void init_taskbarname(); void init_taskbarname_panel(void *p); void draw_taskbarname(void *obj, cairo_t *c);
M src/tint.csrc/tint.c

@@ -372,8 +372,10 @@

Taskbar * drag_taskbar = (Taskbar*)task_drag->area.parent; drag_taskbar->area.list = g_slist_remove(drag_taskbar->area.list, task_drag); - if(event_taskbar->area.posx > drag_taskbar->area.posx || event_taskbar->area.posy > drag_taskbar->area.posy) - event_taskbar->area.list = g_slist_prepend(event_taskbar->area.list, task_drag); + if(event_taskbar->area.posx > drag_taskbar->area.posx || event_taskbar->area.posy > drag_taskbar->area.posy) { + int i = (taskbarname_enabled) ? 1 : 0; + event_taskbar->area.list = g_slist_insert(event_taskbar->area.list, task_drag, i); + } else event_taskbar->area.list = g_slist_append(event_taskbar->area.list, task_drag);

@@ -524,7 +526,9 @@ Task *tsk;

GSList *l; if (server.nb_desktop > old_desktop) { tskbar = &panel->taskbar[old_desktop]; - for (l = tskbar->area.list; l ; l = l->next) { + l = tskbar->area.list; + if (taskbarname_enabled) l = l->next; + for (; l ; l = l->next) { tsk = l->data; if (tsk->desktop == ALLDESKTOP) { tsk->area.on_screen = 0;

@@ -534,7 +538,9 @@ }

} } tskbar = &panel->taskbar[server.desktop]; - for (l = tskbar->area.list; l ; l = l->next) { + l = tskbar->area.list; + if (taskbarname_enabled) l = l->next; + for (; l ; l = l->next) { tsk = l->data; if (tsk->desktop == ALLDESKTOP) { tsk->area.on_screen = 1;
M src/util/area.csrc/util/area.c

@@ -96,9 +96,9 @@

void rendering(void *obj) { Panel *panel = (Panel*)obj; - + size_by_content(&panel->area); - size_by_layout(&panel->area, 0, 0); + size_by_layout(&panel->area, 0, 1); refresh(&panel->area); }

@@ -175,7 +175,10 @@ child->on_changed = 1;

} } - //printf("level %d, object %d, pos %d\n", level, i, pos); + /*// position of each visible object + int k; + for (k=0 ; k < level ; k++) printf(" "); + printf("tree level %d, object %d, pos %d, %s\n", level, i, pos, (child->size_mode == SIZE_BY_LAYOUT) ? "SIZE_BY_LAYOUT" : "SIZE_BY_CONTENT");*/ size_by_layout(child, pos, level+1); if (panel_horizontal)

@@ -239,9 +242,9 @@ }

if (child->on_screen && child->size_mode == SIZE_BY_LAYOUT) nb_by_layout++; } + //printf(" resize_by_layout Deb %d, %d\n", nb_by_content, nb_by_layout); if (nb_by_content+nb_by_layout) size -= ((nb_by_content+nb_by_layout-1) * a->paddingx); - //printf("resize_panel : size_panel %d, size_layout %d\n", panel->area.width, size); int width=0, modulo=0, old_width; if (nb_by_layout) {