Taskbar: code cleanup
This commit is contained in:
parent
92bd9e9184
commit
650806525a
2 changed files with 28 additions and 34 deletions
|
@ -46,8 +46,8 @@ Alignment taskbar_alignment;
|
||||||
|
|
||||||
void taskbar_init_fonts();
|
void taskbar_init_fonts();
|
||||||
|
|
||||||
// Removes the task with &win = key.
|
// Removes the task with &win = key. The other args are ignored.
|
||||||
void taskbar_remove_task(gpointer key, gpointer value, gpointer user_data);
|
void taskbar_remove_task(Window *win);
|
||||||
|
|
||||||
guint win_hash(gconstpointer key)
|
guint win_hash(gconstpointer key)
|
||||||
{
|
{
|
||||||
|
@ -88,7 +88,7 @@ void cleanup_taskbar()
|
||||||
|
|
||||||
g_hash_table_iter_init(&iter, win_to_task);
|
g_hash_table_iter_init(&iter, win_to_task);
|
||||||
if (g_hash_table_iter_next(&iter, &key, &value)) {
|
if (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||||
taskbar_remove_task(key, 0, 0);
|
taskbar_remove_task(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_hash_table_destroy(win_to_task);
|
g_hash_table_destroy(win_to_task);
|
||||||
|
@ -322,9 +322,9 @@ void taskbar_default_font_changed()
|
||||||
panel_refresh = TRUE;
|
panel_refresh = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taskbar_remove_task(gpointer key, gpointer value, gpointer user_data)
|
void taskbar_remove_task(Window *win)
|
||||||
{
|
{
|
||||||
remove_task(get_task(*(Window *)key));
|
remove_task(get_task(*win));
|
||||||
}
|
}
|
||||||
|
|
||||||
Task *get_task(Window win)
|
Task *get_task(Window win)
|
||||||
|
@ -360,7 +360,7 @@ void taskbar_refresh_tasklist()
|
||||||
if (*((Window *)it->data) == win[i])
|
if (*((Window *)it->data) == win[i])
|
||||||
break;
|
break;
|
||||||
if (i == num_results)
|
if (i == num_results)
|
||||||
taskbar_remove_task(it->data, 0, 0);
|
taskbar_remove_task(it->data);
|
||||||
}
|
}
|
||||||
g_list_free(win_list);
|
g_list_free(win_list);
|
||||||
|
|
||||||
|
@ -461,13 +461,13 @@ gint compare_tasks_trivial(Task *a, Task *b, Taskbar *taskbar)
|
||||||
return NONTRIVIAL;
|
return NONTRIVIAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint contained_within(Task *a, Task *b)
|
gboolean contained_within(Task *a, Task *b)
|
||||||
{
|
{
|
||||||
if ((a->win_x <= b->win_x) && (a->win_y <= b->win_y) && (a->win_x + a->win_w >= b->win_x + b->win_w) &&
|
if ((a->win_x <= b->win_x) && (a->win_y <= b->win_y) && (a->win_x + a->win_w >= b->win_x + b->win_w) &&
|
||||||
(a->win_y + a->win_h >= b->win_y + b->win_h)) {
|
(a->win_y + a->win_h >= b->win_y + b->win_h)) {
|
||||||
return 1;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return 0;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gint compare_task_centers(Task *a, Task *b, Taskbar *taskbar)
|
gint compare_task_centers(Task *a, Task *b, Taskbar *taskbar)
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
#include "taskbarname.h"
|
#include "taskbarname.h"
|
||||||
|
|
||||||
int taskbarname_enabled;
|
gboolean taskbarname_enabled;
|
||||||
Color taskbarname_font;
|
Color taskbarname_font;
|
||||||
Color taskbarname_active_font;
|
Color taskbarname_active_font;
|
||||||
|
|
||||||
|
@ -40,23 +40,22 @@ void taskbarname_init_fonts();
|
||||||
|
|
||||||
void default_taskbarname()
|
void default_taskbarname()
|
||||||
{
|
{
|
||||||
taskbarname_enabled = 0;
|
taskbarname_enabled = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_taskbarname_panel(void *p)
|
void init_taskbarname_panel(void *p)
|
||||||
{
|
{
|
||||||
Panel *panel = (Panel *)p;
|
|
||||||
Taskbar *taskbar;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
if (!taskbarname_enabled)
|
if (!taskbarname_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Panel *panel = (Panel *)p;
|
||||||
|
|
||||||
taskbarname_init_fonts();
|
taskbarname_init_fonts();
|
||||||
|
|
||||||
GSList *l, *list = get_desktop_names();
|
GSList *list = get_desktop_names();
|
||||||
for (j = 0, l = list; j < panel->num_desktops; j++) {
|
GSList *l = list;
|
||||||
taskbar = &panel->taskbar[j];
|
for (int j = 0; j < panel->num_desktops; j++) {
|
||||||
|
Taskbar *taskbar = &panel->taskbar[j];
|
||||||
memcpy(&taskbar->bar_name.area, &panel->g_taskbar.area_name, sizeof(Area));
|
memcpy(&taskbar->bar_name.area, &panel->g_taskbar.area_name, sizeof(Area));
|
||||||
taskbar->bar_name.area.parent = taskbar;
|
taskbar->bar_name.area.parent = taskbar;
|
||||||
taskbar->bar_name.area.has_mouse_over_effect = panel_config.mouse_effects;
|
taskbar->bar_name.area.has_mouse_over_effect = panel_config.mouse_effects;
|
||||||
|
@ -70,8 +69,9 @@ void init_taskbarname_panel(void *p)
|
||||||
if (l) {
|
if (l) {
|
||||||
taskbar->bar_name.name = g_strdup(l->data);
|
taskbar->bar_name.name = g_strdup(l->data);
|
||||||
l = l->next;
|
l = l->next;
|
||||||
} else
|
} else {
|
||||||
taskbar->bar_name.name = g_strdup_printf("%d", j + 1);
|
taskbar->bar_name.name = g_strdup_printf("%d", j + 1);
|
||||||
|
}
|
||||||
|
|
||||||
// append the name at the beginning of taskbar
|
// append the name at the beginning of taskbar
|
||||||
taskbar->area.children = g_list_append(taskbar->area.children, &taskbar->bar_name);
|
taskbar->area.children = g_list_append(taskbar->area.children, &taskbar->bar_name);
|
||||||
|
@ -114,14 +114,10 @@ void taskbarname_default_font_changed()
|
||||||
|
|
||||||
void cleanup_taskbarname()
|
void cleanup_taskbarname()
|
||||||
{
|
{
|
||||||
int i, j;
|
for (int i = 0; i < num_panels; i++) {
|
||||||
Panel *panel;
|
Panel *panel = &panels[i];
|
||||||
Taskbar *taskbar;
|
for (int j = 0; j < panel->num_desktops; j++) {
|
||||||
|
Taskbar *taskbar = &panel->taskbar[j];
|
||||||
for (i = 0; i < num_panels; i++) {
|
|
||||||
panel = &panels[i];
|
|
||||||
for (j = 0; j < panel->num_desktops; j++) {
|
|
||||||
taskbar = &panel->taskbar[j];
|
|
||||||
g_free(taskbar->bar_name.name);
|
g_free(taskbar->bar_name.name);
|
||||||
taskbar->bar_name.name = NULL;
|
taskbar->bar_name.name = NULL;
|
||||||
free_area(&taskbar->bar_name.area);
|
free_area(&taskbar->bar_name.area);
|
||||||
|
@ -135,7 +131,7 @@ gboolean resize_taskbarname(void *obj)
|
||||||
TaskbarName *taskbar_name = obj;
|
TaskbarName *taskbar_name = obj;
|
||||||
Panel *panel = taskbar_name->area.panel;
|
Panel *panel = taskbar_name->area.panel;
|
||||||
int name_height, name_width, name_height_ink;
|
int name_height, name_width, name_height_ink;
|
||||||
int ret = 0;
|
gboolean result = FALSE;
|
||||||
|
|
||||||
schedule_redraw(&taskbar_name->area);
|
schedule_redraw(&taskbar_name->area);
|
||||||
get_text_size2(panel_config.taskbarname_font_desc,
|
get_text_size2(panel_config.taskbarname_font_desc,
|
||||||
|
@ -155,28 +151,27 @@ gboolean resize_taskbarname(void *obj)
|
||||||
if (new_size != taskbar_name->area.width) {
|
if (new_size != taskbar_name->area.width) {
|
||||||
taskbar_name->area.width = new_size;
|
taskbar_name->area.width = new_size;
|
||||||
taskbar_name->posy = (taskbar_name->area.height - name_height) / 2;
|
taskbar_name->posy = (taskbar_name->area.height - name_height) / 2;
|
||||||
ret = 1;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int new_size = name_height + (2 * (taskbar_name->area.paddingxlr + taskbar_name->area.bg->border.width));
|
int new_size = name_height + (2 * (taskbar_name->area.paddingxlr + taskbar_name->area.bg->border.width));
|
||||||
if (new_size != taskbar_name->area.height) {
|
if (new_size != taskbar_name->area.height) {
|
||||||
taskbar_name->area.height = new_size;
|
taskbar_name->area.height = new_size;
|
||||||
taskbar_name->posy = (taskbar_name->area.height - name_height) / 2;
|
taskbar_name->posy = (taskbar_name->area.height - name_height) / 2;
|
||||||
ret = 1;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_taskbarname(void *obj, cairo_t *c)
|
void draw_taskbarname(void *obj, cairo_t *c)
|
||||||
{
|
{
|
||||||
TaskbarName *taskbar_name = obj;
|
TaskbarName *taskbar_name = obj;
|
||||||
Taskbar *taskbar = taskbar_name->area.parent;
|
Taskbar *taskbar = taskbar_name->area.parent;
|
||||||
PangoLayout *layout;
|
|
||||||
Color *config_text = (taskbar->desktop == server.desktop) ? &taskbarname_active_font : &taskbarname_font;
|
Color *config_text = (taskbar->desktop == server.desktop) ? &taskbarname_active_font : &taskbarname_font;
|
||||||
|
|
||||||
// draw content
|
// draw content
|
||||||
layout = pango_cairo_create_layout(c);
|
PangoLayout *layout = pango_cairo_create_layout(c);
|
||||||
pango_layout_set_font_description(layout, panel_config.taskbarname_font_desc);
|
pango_layout_set_font_description(layout, panel_config.taskbarname_font_desc);
|
||||||
pango_layout_set_width(layout, taskbar_name->area.width * PANGO_SCALE);
|
pango_layout_set_width(layout, taskbar_name->area.width * PANGO_SCALE);
|
||||||
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
|
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
|
||||||
|
@ -190,5 +185,4 @@ void draw_taskbarname(void *obj, cairo_t *c)
|
||||||
draw_text(layout, c, 0, taskbar_name->posy, config_text, ((Panel *)taskbar_name->area.panel)->font_shadow);
|
draw_text(layout, c, 0, taskbar_name->posy, config_text, ((Panel *)taskbar_name->area.panel)->font_shadow);
|
||||||
|
|
||||||
g_object_unref(layout);
|
g_object_unref(layout);
|
||||||
// printf("draw_taskbarname %s ******************************\n", taskbar_name->name);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue