]>
Dogcows Code - chaz/tint2/blob - src/taskbar/task.c
1 /**************************************************************************
5 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
6 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
22 #include <X11/Xutil.h>
23 #include <X11/Xatom.h>
37 Task
*add_task (Window win
)
40 if (window_is_hidden(win
)) return 0;
46 new_tsk
.area
.panel
= &panel1
[0];
47 new_tsk
.desktop
= window_get_desktop (win
);
48 if (nb_panel
> 1) monitor
= window_get_monitor (win
);
51 // allocate only one title and one icon
52 // even with task_on_all_desktop and with task_on_all_panel
54 new_tsk
.icon
= new_tsk
.icon_active
= NULL
;
58 //printf("task %s : desktop %d, monitor %d\n", new_tsk->title, desktop, monitor);
59 XSelectInput (server
.dsp
, new_tsk
.win
, PropertyChangeMask
|StructureNotifyMask
);
64 for (i
= 0; i
< nb_panel
; i
++) {
65 if (nb_panel
> 1 && panel1
[i
].monitor
!= monitor
) continue;
66 for (j
= 0; j
< panel1
[i
].nb_desktop
; j
++) {
67 if ((new_tsk
.desktop
!= ALLDESKTOP
&& new_tsk
.desktop
!= j
)
68 || (panel_mode
== MULTI_DESKTOP
&& new_tsk
.desktop
== ALLDESKTOP
&& server
.desktop
!= j
))
70 // for (i=0 ; i < nb_panel ; i++) {
71 // for (j=0 ; j < panel1[i].nb_desktop ; j++) {
72 // if (new_tsk.desktop != ALLDESKTOP && new_tsk.desktop != j) continue;
73 // if (nb_panel > 1 && panel1[i].monitor != monitor) continue;
75 tskbar
= &panel1
[i
].taskbar
[j
];
76 new_tsk2
= malloc(sizeof(Task
));
77 memcpy(&new_tsk2
->area
, &panel1
[i
].g_task
.area
, sizeof(Area
));
78 new_tsk2
->area
.parent
= tskbar
;
79 new_tsk2
->win
= new_tsk
.win
;
80 new_tsk2
->desktop
= new_tsk
.desktop
;
81 new_tsk2
->title
= new_tsk
.title
;
82 new_tsk2
->icon
= new_tsk
.icon
;
83 new_tsk2
->icon_active
= new_tsk
.icon_active
;
84 new_tsk2
->icon_width
= new_tsk
.icon_width
;
85 new_tsk2
->icon_height
= new_tsk
.icon_height
;
86 tskbar
->area
.list
= g_slist_append(tskbar
->area
.list
, new_tsk2
);
87 tskbar
->area
.resize
= 1;
88 //printf("add_task panel %d, desktop %d, task %s\n", i, j, new_tsk2->title);
95 void remove_task (Task
*tsk
)
99 Window win
= tsk
->win
;
100 int desktop
= tsk
->desktop
;
102 // free title and icon just for the first task
103 // even with task_on_all_desktop and with task_on_all_panel
104 //printf("remove_task %s %d\n", tsk->title, tsk->desktop);
108 imlib_context_set_image(tsk
->icon
);
110 imlib_context_set_image(tsk
->icon_active
);
112 tsk
->icon
= tsk
->icon_active
= NULL
;
118 for (i
=0 ; i
< nb_panel
; i
++) {
119 for (j
=0 ; j
< panel1
[i
].nb_desktop
; j
++) {
120 if (desktop
!= ALLDESKTOP
&& desktop
!= j
) continue;
123 tskbar
= &panel1
[i
].taskbar
[j
];
124 for (l0
= tskbar
->area
.list
; l0
; ) {
127 if (win
== tsk2
->win
) {
128 tskbar
->area
.list
= g_slist_remove(tskbar
->area
.list
, tsk2
);
129 tskbar
->area
.resize
= 1;
131 if (tsk2
== task_active
)
133 if (tsk2
== task_drag
)
136 XFreePixmap (server
.dsp
, tsk2
->area
.pix
.pmap
);
137 XFreePixmap (server
.dsp
, tsk2
->area
.pix_active
.pmap
);
146 void get_title(Task
*tsk
)
148 Panel
*panel
= tsk
->area
.panel
;
151 if (!panel
->g_task
.text
&& !g_tooltip
.enabled
) return;
153 name
= server_get_property (tsk
->win
, server
.atom
._NET_WM_VISIBLE_NAME
, server
.atom
.UTF8_STRING
, 0);
154 if (!name
|| !strlen(name
)) {
155 name
= server_get_property (tsk
->win
, server
.atom
._NET_WM_NAME
, server
.atom
.UTF8_STRING
, 0);
156 if (!name
|| !strlen(name
)) {
157 name
= server_get_property (tsk
->win
, server
.atom
.WM_NAME
, XA_STRING
, 0);
158 if (!name
|| !strlen(name
)) {
160 strcpy(name
, "Untitled");
165 // add space before title
166 title
= malloc(strlen(name
)+2);
167 if (panel
->g_task
.icon
) strcpy(title
, " ");
170 if (name
) XFree (name
);
172 tsk
->area
.redraw
= 1;
179 void get_icon (Task
*tsk
)
181 Panel
*panel
= tsk
->area
.panel
;
182 if (!panel
->g_task
.icon
) return;
185 imlib_context_set_image(tsk
->icon
);
187 imlib_context_set_image(tsk
->icon_active
);
189 tsk
->icon
= tsk
->icon_active
= NULL
;
191 tsk
->area
.redraw
= 1;
194 Imlib_Image img
= NULL
;
195 long *data
= server_get_property (tsk
->win
, server
.atom
._NET_WM_ICON
, XA_CARDINAL
, &i
);
201 tmp_data
= get_best_icon (data
, get_icon_count (data
, i
), i
, &w
, &h
, panel
->g_task
.icon_size1
);
204 DATA32
*icon_data
= malloc (w
* h
* sizeof (DATA32
));
206 for (i
= 0; i
< length
; ++i
)
207 icon_data
[i
] = tmp_data
[i
];
208 img
= imlib_create_image_using_data (w
, h
, icon_data
);
211 img
= imlib_create_image_using_data (w
, h
, (DATA32
*)tmp_data
);
217 XWMHints
*hints
= XGetWMHints(server
.dsp
, tsk
->win
);
219 if (hints
->flags
& IconPixmapHint
&& hints
->icon_pixmap
!= 0) {
220 // get width, height and depth for the pixmap
223 uint border_width
, bpp
;
226 //printf(" get pixmap\n");
227 XGetGeometry(server
.dsp
, hints
->icon_pixmap
, &root
, &icon_x
, &icon_y
, &w
, &h
, &border_width
, &bpp
);
228 imlib_context_set_drawable(hints
->icon_pixmap
);
229 img
= imlib_create_image_from_drawable(hints
->icon_mask
, 0, 0, w
, h
, 0);
235 imlib_context_set_image(default_icon
);
236 img
= imlib_clone_image();
240 imlib_context_set_image(img
);
241 imlib_image_set_has_alpha(1);
242 tsk
->icon
= imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), panel
->g_task
.icon_size1
, panel
->g_task
.icon_size1
);
245 imlib_context_set_image(tsk
->icon
);
246 tsk
->icon_width
= imlib_image_get_width();
247 tsk
->icon_height
= imlib_image_get_height();
248 tsk
->icon_active
= imlib_clone_image();
251 if (panel
->g_task
.alpha
!= 100 || panel
->g_task
.saturation
!= 0 || panel
->g_task
.brightness
!= 0) {
252 data32
= imlib_image_get_data();
253 adjust_asb(data32
, tsk
->icon_width
, tsk
->icon_height
, panel
->g_task
.alpha
, (float)panel
->g_task
.saturation
/100, (float)panel
->g_task
.brightness
/100);
254 imlib_image_put_back_data(data32
);
257 if (panel
->g_task
.alpha_active
!= 100 || panel
->g_task
.saturation_active
!= 0 || panel
->g_task
.brightness_active
!= 0) {
258 imlib_context_set_image(tsk
->icon_active
);
259 data32
= imlib_image_get_data();
260 adjust_asb(data32
, tsk
->icon_width
, tsk
->icon_height
, panel
->g_task
.alpha_active
, (float)panel
->g_task
.saturation_active
/100, (float)panel
->g_task
.brightness_active
/100);
261 imlib_image_put_back_data(data32
);
266 void draw_task_icon (Task
*tsk
, int text_width
, int active
)
268 if (tsk
->icon
== NULL
|| tsk
->icon_active
== NULL
) return;
272 Panel
*panel
= (Panel
*)tsk
->area
.panel
;
273 if (panel
->g_task
.centered
) {
274 if (panel
->g_task
.text
)
275 pos_x
= (tsk
->area
.width
- text_width
- panel
->g_task
.icon_size1
) / 2;
277 pos_x
= (tsk
->area
.width
- panel
->g_task
.icon_size1
) / 2;
279 else pos_x
= panel
->g_task
.area
.paddingxlr
+ panel
->g_task
.area
.pix
.border
.width
;
284 imlib_context_set_image (tsk
->icon
);
285 pmap
= &tsk
->area
.pix
.pmap
;
288 imlib_context_set_image (tsk
->icon_active
);
289 pmap
= &tsk
->area
.pix_active
.pmap
;
291 imlib_context_set_drawable (*pmap
);
292 imlib_render_image_on_drawable (pos_x
, panel
->g_task
.icon_posy
);
296 void draw_task (void *obj
, cairo_t
*c
, int active
)
300 config_color
*config_text
;
302 Panel
*panel
= (Panel
*)tsk
->area
.panel
;
304 if (panel
->g_task
.text
) {
306 layout
= pango_cairo_create_layout (c
);
307 pango_layout_set_font_description (layout
, panel
->g_task
.font_desc
);
308 pango_layout_set_text (layout
, tsk
->title
, -1);
310 /* Drawing width and Cut text */
311 // pango use U+22EF or U+2026
312 pango_layout_set_width (layout
, ((Taskbar
*)tsk
->area
.parent
)->text_width
* PANGO_SCALE
);
313 pango_layout_set_ellipsize (layout
, PANGO_ELLIPSIZE_END
);
316 if (panel
->g_task
.centered
) pango_layout_set_alignment (layout
, PANGO_ALIGN_CENTER
);
317 else pango_layout_set_alignment (layout
, PANGO_ALIGN_LEFT
);
319 pango_layout_get_pixel_size (layout
, &width
, &height
);
321 if (active
) config_text
= &panel
->g_task
.font_active
;
322 else config_text
= &panel
->g_task
.font
;
324 cairo_set_source_rgba (c
, config_text
->color
[0], config_text
->color
[1], config_text
->color
[2], config_text
->alpha
);
326 pango_cairo_update_layout (c
, layout
);
327 cairo_move_to (c
, panel
->g_task
.text_posx
, panel
->g_task
.text_posy
);
328 pango_cairo_show_layout (c
, layout
);
330 if (panel
->g_task
.font_shadow
) {
331 cairo_set_source_rgba (c
, 0.0, 0.0, 0.0, 0.5);
332 pango_cairo_update_layout (c
, layout
);
333 cairo_move_to (c
, panel
->g_task
.text_posx
+ 1, panel
->g_task
.text_posy
+ 1);
334 pango_cairo_show_layout (c
, layout
);
336 g_object_unref (layout
);
339 if (panel
->g_task
.icon
) {
340 // icon use same opacity as text
341 draw_task_icon (tsk
, width
, active
);
This page took 0.051639 seconds and 5 git commands to generate.