]> Dogcows Code - chaz/tint2/blob - src/taskbar/taskbarname.c
desktop name: first step
[chaz/tint2] / src / taskbar / taskbarname.c
1 /**************************************************************************
2 *
3 * Tint2 : taskbarname
4 *
5 * Copyright (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr) from Omega distribution
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 **************************************************************************/
19
20 #include <X11/Xlib.h>
21 #include <X11/Xutil.h>
22 #include <X11/Xatom.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <glib.h>
27 #include <Imlib2.h>
28
29 #include "window.h"
30 #include "panel.h"
31 #include "taskbar.h"
32 #include "server.h"
33 #include "taskbarname.h"
34
35 int taskbarname_enabled;
36 PangoFontDescription *taskbarname_font_desc;
37 Color taskbarname_font;
38
39
40 void default_taskbarname()
41 {
42 taskbarname_enabled = 0;
43 taskbarname_font_desc = 0;
44 }
45
46
47 void init_taskbarname_panel(void *p)
48 {
49 Panel *panel =(Panel*)p;
50 int j;
51
52 if (!taskbarname_enabled || !taskbar_enabled) return;
53
54 for (j=0 ; j < panel->nb_desktop ; j++) {
55 panel->taskbar[j].bar_name.name = g_strdup_printf("%d", j+1);
56 }
57 }
58
59
60 void cleanup_taskbarname()
61 {
62 int i, j, k;
63 Panel *panel;
64 Taskbar *tskbar;
65
66 for (i=0 ; i < nb_panel ; i++) {
67 panel = &panel1[i];
68 for (j=0 ; j < panel->nb_desktop ; j++) {
69 tskbar = &panel->taskbar[j];
70 if (taskbarname_font_desc) pango_font_description_free(taskbarname_font_desc);
71 if (tskbar->bar_name.name) g_free(tskbar->bar_name.name);
72 free_area (&tskbar->bar_name.area);
73 for (k=0; k<TASKBAR_STATE_COUNT; ++k) {
74 if (tskbar->bar_name.state_pix[k]) XFreePixmap(server.dsp, tskbar->bar_name.state_pix[k]);
75 }
76 }
77 }
78 }
79
80
81 void draw_taskbarname (void *obj, cairo_t *c)
82 {
83 Taskbarname *taskbar_name = obj;
84 PangoLayout *layout;
85
86 layout = pango_cairo_create_layout (c);
87
88 // draw layout
89 pango_layout_set_font_description (layout, taskbarname_font_desc);
90 pango_layout_set_width (layout, taskbar_name->area.width * PANGO_SCALE);
91 pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
92 pango_layout_set_text (layout, taskbar_name->name, strlen(taskbar_name->name));
93
94 cairo_set_source_rgba (c, taskbarname_font.color[0], taskbarname_font.color[1], taskbarname_font.color[2], taskbarname_font.alpha);
95
96 pango_cairo_update_layout (c, layout);
97 cairo_move_to (c, 0, 2);
98 pango_cairo_show_layout (c, layout);
99
100 g_object_unref (layout);
101 printf("draw_taskbarname %s ******************************\n", taskbar_name->name);
102 }
103
104
105 int resize_taskbarname(void *obj)
106 {
107 Taskbarname *taskbar_name = (Taskbar*)obj;
108 Panel *panel = taskbar_name->area.panel;
109 int time_height, time_width, ret = 0;
110
111 taskbar_name->area.redraw = 1;
112 /*
113 strftime(buf_time, sizeof(buf_time), time1_format, clock_gettime_for_tz(time1_timezone));
114 get_text_size2(time1_font_desc, &time_height_ink, &time_height, &time_width, panel->area.height, panel->area.width, buf_time, strlen(buf_time));
115 if (time2_format) {
116 strftime(buf_date, sizeof(buf_date), time2_format, clock_gettime_for_tz(time2_timezone));
117 get_text_size2(time2_font_desc, &date_height_ink, &date_height, &date_width, panel->area.height, panel->area.width, buf_date, strlen(buf_date));
118 }
119
120 if (panel_horizontal) {
121 int new_size = (time_width > date_width) ? time_width : date_width;
122 new_size += (2*clock->area.paddingxlr) + (2*clock->area.bg->border.width);
123 if (new_size > clock->area.width || new_size < (clock->area.width-6)) {
124 // we try to limit the number of resize
125 clock->area.width = new_size + 1;
126 clock->time1_posy = (clock->area.height - time_height) / 2;
127 if (time2_format) {
128 clock->time1_posy -= ((date_height_ink + 2) / 2);
129 clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2;
130 }
131 ret = 1;
132 }
133 }
134 else {
135 int new_size = time_height + date_height + (2 * (clock->area.paddingxlr + clock->area.bg->border.width));
136 if (new_size != clock->area.height) {
137 // we try to limit the number of resize
138 clock->area.height = new_size;
139 clock->time1_posy = (clock->area.height - time_height) / 2;
140 if (time2_format) {
141 clock->time1_posy -= ((date_height_ink + 2) / 2);
142 clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2;
143 }
144 ret = 1;
145 }
146 }
147 return ret;
148 */
149
150 taskbar_name->area.width = 10;
151 return 1;
152 }
153
154
155
156
This page took 0.04147 seconds and 4 git commands to generate.