desktop name: first step

git-svn-id: http://tint2.googlecode.com/svn/trunk@596 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
thilor77 2010-11-13 10:27:26 +00:00
parent a7a2ae337a
commit d94e2a1790
9 changed files with 199 additions and 65 deletions

View file

@ -467,12 +467,23 @@ void add_entry (char *key, char *value)
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) {
}

View file

@ -169,9 +169,6 @@ void init_panel()
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 @@ void set_panel_background(Panel *p)
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 @@ Task *click_task (Panel *panel, int x, int y)
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 @@ Task *click_task (Panel *panel, int x, int y)
}
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;

View file

@ -414,7 +414,9 @@ Task *next_task(Task *tsk)
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 *prev_task(Task *tsk)
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) {

View file

@ -54,6 +54,7 @@ void default_taskbar()
urgent_timeout = 0;
urgent_list = 0;
taskbar_enabled = 0;
default_taskbarname();
}
void cleanup_taskbar()
@ -62,6 +63,7 @@ void cleanup_taskbar()
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 @@ void init_taskbar_panel(void *p)
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 @@ void init_taskbar_panel(void *p)
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 @@ int resize_taskbar(void *obj)
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 @@ void set_taskbar_state(Taskbar *tskbar, int state)
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);
}
}

View file

@ -9,6 +9,7 @@
#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 @@ typedef struct {
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;

View file

@ -26,57 +26,129 @@
#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;
}
void cleanup_taskbarname()
{
Panel *panel;
Taskbar *tskbar;
int i, j;
for (i=0 ; i < nb_panel ; i++) {
panel = &panel1[i];
}
}
void init_taskbarname()
{
taskbarname_font_desc = 0;
}
void init_taskbarname_panel(void *p)
{
Panel *panel =(Panel*)p;
int j;
if (!taskbarname_enabled) return;
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;
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 draw_taskbarname (void *obj, cairo_t *c)
{
Taskbarname *taskbar_name = obj;
PangoLayout *layout;
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);
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;
return 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;
*/
taskbar_name->area.width = 10;
return 1;
}

View file

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

View file

@ -372,8 +372,10 @@ void event_button_motion_notify (XEvent *e)
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 @@ void event_property_notify (XEvent *e)
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 @@ void event_property_notify (XEvent *e)
}
}
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;

View file

@ -96,9 +96,9 @@ void init_rendering(void *obj, int pos)
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 @@ void size_by_layout (Area *a, int pos, int level)
}
}
//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 @@ int resize_by_layout(void *obj, int maximum_size)
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) {