From 9a6f8801012c62445afd308a733aed5fc3bb7716 Mon Sep 17 00:00:00 2001 From: Thierry Lorthiois Date: Tue, 16 Nov 2010 20:00:22 +0000 Subject: [PATCH] desktop name : last step --- src/taskbar/taskbarname.c | 27 ++++++++------------------- src/tint.c | 27 ++++++++++++++++++++++++++- src/util/window.c | 20 ++++++++++++++++++++ src/util/window.h | 2 ++ 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/src/taskbar/taskbarname.c b/src/taskbar/taskbarname.c index 2cde28b..12866c7 100644 --- a/src/taskbar/taskbarname.c +++ b/src/taskbar/taskbarname.c @@ -49,25 +49,11 @@ void init_taskbarname_panel(void *p) { Panel *panel =(Panel*)p; Taskbar *tskbar; - int j, count; + int j; if (!taskbarname_enabled) return; - GList *list = NULL; - gchar *data_ptr, *ptr; - data_ptr = server_get_property (server.root_win, server.atom._NET_DESKTOP_NAMES, server.atom.UTF8_STRING, &count); - if (data_ptr) { - list = g_list_append(list, g_strdup(data_ptr)); - for (j = 0; j < count-1; j++) { - if (*(data_ptr + j) == '\0') { - ptr = (gchar*)data_ptr + j + 1; - list = g_list_append(list, g_strdup(ptr)); - } - } - XFree(data_ptr); - } - - GList *l; + GSList *l, *list = server_get_name_of_desktop(); for (j=0, l=list ; j < panel->nb_desktop ; j++) { tskbar = &panel->taskbar[j]; memcpy(&tskbar->bar_name.area, &panel->g_taskbar.area_name, sizeof(Area)); @@ -77,18 +63,21 @@ void init_taskbarname_panel(void *p) else tskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_NORMAL]; + // use desktop number if name is missing if (l) { tskbar->bar_name.name = g_strdup(l->data); l = l->next; } - else { - // use desktop number if name is missing + else tskbar->bar_name.name = g_strdup_printf("%d", j+1); - } // append the name at the beginning of taskbar tskbar->area.list = g_slist_append(tskbar->area.list, &tskbar->bar_name); } + + for (l=list ; l ; l = l->next) + g_free(l->data); + g_slist_free(list); } diff --git a/src/tint.c b/src/tint.c index 536cbc3..5d5720c 100644 --- a/src/tint.c +++ b/src/tint.c @@ -492,7 +492,32 @@ void event_property_notify (XEvent *e) // Change name of desktops else if (at == server.atom._NET_DESKTOP_NAMES) { - printf("_NET_DESKTOP_NAMES\n"); + if (!taskbarname_enabled) return; + GSList *l, *list = server_get_name_of_desktop(); + int j; + gchar *name; + Taskbar *tskbar; + for (i=0 ; i < nb_panel ; i++) { + for (j=0, l=list ; j < panel1[i].nb_desktop ; j++) { + if (l) { + name = g_strdup(l->data); + l = l->next; + } + else + name = g_strdup_printf("%d", j+1); + tskbar = &panel1[i].taskbar[j]; + if (strcmp(name, tskbar->bar_name.name) != 0) { + g_free(tskbar->bar_name.name); + tskbar->bar_name.name = name; + tskbar->bar_name.area.resize = 1; + } + else + g_free(name); + } + } + for (l=list ; l ; l = l->next) + g_free(l->data); + g_slist_free(list); panel_refresh = 1; } // Change number of desktops diff --git a/src/util/window.c b/src/util/window.c index ef38071..ac2b400 100644 --- a/src/util/window.c +++ b/src/util/window.c @@ -203,6 +203,26 @@ int server_get_number_of_desktop () } +GSList *server_get_name_of_desktop () +{ + int count, j; + GSList *list = NULL; + gchar *data_ptr, *ptr; + data_ptr = server_get_property (server.root_win, server.atom._NET_DESKTOP_NAMES, server.atom.UTF8_STRING, &count); + if (data_ptr) { + list = g_slist_append(list, g_strdup(data_ptr)); + for (j = 0; j < count-1; j++) { + if (*(data_ptr + j) == '\0') { + ptr = (gchar*)data_ptr + j + 1; + list = g_slist_append(list, g_strdup(ptr)); + } + } + XFree(data_ptr); + } + return list; +} + + int server_get_current_desktop () { return get_property32(server.root_win, server.atom._NET_CURRENT_DESKTOP, XA_CARDINAL); diff --git a/src/util/window.h b/src/util/window.h index db6d3a9..fcf666f 100644 --- a/src/util/window.h +++ b/src/util/window.h @@ -9,6 +9,7 @@ #ifndef WINDOW_H #define WINDOW_H +#include #include @@ -17,6 +18,7 @@ void set_desktop (int desktop); void set_close (Window win); int server_get_current_desktop (); int server_get_number_of_desktop (); +GSList *server_get_name_of_desktop (); int window_is_iconified (Window win); int window_is_urgent (Window win); int window_is_hidden (Window win); -- 2.45.2