]>
Dogcows Code - chaz/tint2/blob - taskbarname.c
ff75893ce8c6f3d7e5e0d91d77b74ba36b753548
1 /**************************************************************************
5 * Copyright (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr) from Omega distribution
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.
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 **************************************************************************/
21 #include <X11/Xutil.h>
22 #include <X11/Xatom.h>
33 #include "taskbarname.h"
35 int taskbarname_enabled
;
36 PangoFontDescription
*taskbarname_font_desc
;
37 Color taskbarname_font
;
40 void default_taskbarname()
42 taskbarname_enabled
= 0;
43 taskbarname_font_desc
= 0;
47 void init_taskbarname_panel(void *p
)
49 Panel
*panel
=(Panel
*)p
;
52 if (!taskbarname_enabled
|| !taskbar_enabled
) return;
54 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
55 panel
->taskbar
[j
].bar_name
.name
= g_strdup_printf("%d", j
+1);
60 void cleanup_taskbarname()
66 if (taskbarname_font_desc
) pango_font_description_free(taskbarname_font_desc
);
67 for (i
=0 ; i
< nb_panel
; i
++) {
69 for (j
=0 ; j
< panel
->nb_desktop
; j
++) {
70 tskbar
= &panel
->taskbar
[j
];
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
]);
81 void draw_taskbarname (void *obj
, cairo_t
*c
)
83 Taskbarname
*taskbar_name
= obj
;
86 layout
= pango_cairo_create_layout (c
);
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
));
94 cairo_set_source_rgba (c
, taskbarname_font
.color
[0], taskbarname_font
.color
[1], taskbarname_font
.color
[2], taskbarname_font
.alpha
);
96 pango_cairo_update_layout (c
, layout
);
97 cairo_move_to (c
, 0, 2);
98 pango_cairo_show_layout (c
, layout
);
100 g_object_unref (layout
);
101 printf("draw_taskbarname %s ******************************\n", taskbar_name
->name
);
105 int resize_taskbarname(void *obj
)
107 Taskbarname
*taskbar_name
= (Taskbar
*)obj
;
108 Panel
*panel
= taskbar_name
->area
.panel
;
109 int time_height
, time_width
, ret
= 0;
111 taskbar_name
->area
.redraw
= 1;
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));
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));
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;
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;
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;
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;
150 taskbar_name
->area
.width
= 10;
This page took 0.043193 seconds and 3 git commands to generate.