21
bool taskInfo::Init(WnckWindow* window)
25
printf("taskInfo::Init NULL argument!\n");
21
bool taskInfo::Init (WnckWindow* window) {
23
printf("taskInfo::Init NULL argument!\n");
29
27
/*First set the icon. This will work always, as wnck_window_get_icon
30
28
returns a fallbackicon if necessary, the rest may fail*/
31
29
GdkPixbuf* pb = gdk_pixbuf_copy(wnck_window_get_icon (window));
31
wxBitmap* bmp = new wxBitmap(pb);
43
enum { BUFFERSIZE = 1024 };
44
char processName[BUFFERSIZE];
45
/* Since X doesn't rely on pids there's not a clear way to get the
37
enum { BUFFERSIZE = 1024 };
38
char processName[BUFFERSIZE];
39
/* Since X doesn't rely on pids there's not a clear way to get the
46
40
* pid associated with a window. We use 2 different ways to get the
47
41
* pid. None of them is 100% accurate. (aMSN!!!) */
51
pid = wnck_window_get_pid (window);
43
pid = wnck_window_get_pid (window);
53
WnckApplication *app = wnck_window_get_application (window);
54
pid = wnck_application_get_pid (app);
45
pid = wnck_application_get_pid(wnck_window_get_application(window));
59
printf("Could not get pid for 0x%x\n",(unsigned int) wnck_window_get_xid (window));
49
printf("Could not get pid for 0x%x\n",(unsigned int) wnck_window_get_xid (window));
63
53
if (!tasks_getProcessName(pid, &processName[0], sizeof (processName) -1))
65
printf("Could not get process name for %d\n", pid);
69
setPath(&processName[0]);
70
setName(&processName[0]);
55
printf("Could not get process name for %d\n", pid);
59
setPath(&processName[0]);
60
setName(&processName[0]);
76
bool taskInfo::compareWith (simImage * img)
78
if (name.IsEmpty() || img->link.IsEmpty())
65
bool taskInfo::compareWith (simImage * img) {
66
if (name.IsEmpty() || img->link.IsEmpty()) {
70
if (pid == img->pid) {
89
75
wxFileName launcherFN (img->link);
90
76
wxString currLauncher = launcherFN.GetName ();
91
if (launcherFN.HasExt ())
93
currLauncher = currLauncher + _T (".") + launcherFN.GetExt ();
97
if (currLauncher.Len () > name.Len ()
98
&& currLauncher.StartsWith (name))
101
if (name.StartsWith (currLauncher))
104
if (currLauncher.CmpNoCase (name) == 0)
77
if (launcherFN.HasExt ()) {
78
currLauncher = currLauncher + _T (".") + launcherFN.GetExt ();
82
if ( (currLauncher.Len() > name.Len() && currLauncher.StartsWith(name))
83
|| name.StartsWith(currLauncher)
84
|| currLauncher.CmpNoCase(name) == 0) {
111
void taskInfo::setName (char *processName)
91
void taskInfo::setName (char *processName) {
113
92
wxString s = wxString ((const char *) processName, wxConvUTF8);
114
93
wxFileName programFN (s);
115
94
name = programFN.GetName ();
116
if (programFN.HasExt ())
95
if (programFN.HasExt ()) {
118
96
name = name + _T (".") + programFN.GetExt ();
122
void taskInfo::setPath (char *processName)
100
void taskInfo::setPath (char *processName) {
124
101
path = wxString ((const char *) processName, wxConvUTF8);
129
tasks_getProcessName (unsigned int pid, char *target_name, int size_targetname)
105
int tasks_getProcessName (unsigned int pid, char *target_name, int size_targetname) {
132
107
char dir_name[PATH_MAX];
134
sprintf (dir_name, "/proc/%d/exe", pid);
109
sprintf(dir_name, "/proc/%d/exe", pid);
136
111
/* Getting the target of the exe ie to which binary it points to */
137
target_link = readlink (dir_name, target_name, size_targetname);
112
target_link = readlink(dir_name, target_name, size_targetname);
139
114
if (target_link <= 0) {
177
148
if (img->windowCount() > 0) {
179
150
ti.Init(img->getWindow());
180
img->img = ti.icon.ConvertToImage();
152
// starters still have their own image we prefer to use
153
img->img = ti.icon.ConvertToImage();
183
wxGetApp().refresh();
157
wxGetApp().frame->appSize = FirstPosition(ca->settings, ImagesList);
158
wxGetApp().updateSize();
159
wxGetApp().refresh();
190
static void tasks_window_opened (WnckScreen *screen, WnckWindow *window, callbackArgs* ca )
192
if (!ca || !ca->ImagesList)
194
printf("tasks_window_opened NULL ARGUMENT!\n");
198
ImagesArray * ImagesList = ca->ImagesList;
199
simSettings settings = ca->settings;
201
if (wnck_window_is_skip_tasklist (window))
208
for (i = 0; i < ImagesList->GetCount (); i++)
210
simImage *img = (*ImagesList)[i];
212
if (ti.compareWith (img))
214
img->addWindow(window);
165
static void tasks_window_opened (WnckScreen *screen, WnckWindow *window, callbackArgs* ca) {
166
if (!ca || !ca->ImagesList) {
167
printf("tasks_window_opened NULL ARGUMENT!\n");
171
if (wnck_window_is_skip_tasklist (window)) {
175
ImagesArray * ImagesList = ca->ImagesList;
176
simSettings settings = ca->settings;
181
for (i = 0; i < ImagesList->GetCount (); i++) {
182
simImage *img = (*ImagesList)[i];
184
if (ti.compareWith (img)) {
185
img->addWindow(window);
216
187
// refresh the icon, cause sometimes the splash-screen has not
217
188
// a valid icon, but the program does
218
img->img = ti.icon.ConvertToImage();
219
wxGetApp().refresh();
224
if (i == ImagesList->GetCount())
226
tasks_addNewImage(window, ImagesList, settings, ti);
190
// but don't do that for starters, as we want to preserve their image
191
img->img = ti.icon.ConvertToImage();
193
wxGetApp().refresh();
198
if (i == ImagesList->GetCount()) {
199
tasks_addNewImage(window, ImagesList, settings, ti);
230
void tasks_window_background_change (WnckScreen *screen, WnckWindow *window, callbackArgs* ca )
203
void tasks_window_background_change (WnckScreen *screen, WnckWindow *window, callbackArgs* ca) {
232
204
wxBitmap* backImage = getRootWallpaper();
233
205
wxGetApp().SetWallpaper(backImage);
236
void tasks_track_active_window (WnckScreen *screen, WnckWindow *window, callbackArgs* ca ) {
237
if (!WNCK_IS_WINDOW (window))
241
ImagesArray * ImagesList = ca->ImagesList;
246
if (wnck_window_is_skip_tasklist (window)) {
208
void tasks_track_active_window (WnckScreen *screen, WnckWindow *window, callbackArgs* ca) {
209
if (!WNCK_IS_WINDOW (window)) {
213
ImagesArray * ImagesList = ca->ImagesList;
218
if (wnck_window_is_skip_tasklist (window)) {
247
219
// note that this also catches simdock itself
252
for (i = 0; i < ImagesList->GetCount (); i++)
254
simImage *img = (*ImagesList)[i];
256
if (img->hasWindow(window))
267
void tasks_register_signals(ImagesArray * ImagesList,simSettings settings)
269
callbackArgs* ca = new callbackArgs();
270
ca->ImagesList = ImagesList;
271
ca->settings = settings;
273
WnckScreen *defaultScreen = wnck_screen_get_default ();
274
g_signal_connect (G_OBJECT(defaultScreen), "window_opened",
275
G_CALLBACK (tasks_window_opened),
278
g_signal_connect (G_OBJECT(defaultScreen), "background-changed",
279
G_CALLBACK (tasks_window_background_change),
282
g_signal_connect (G_OBJECT(defaultScreen), "window_closed",
283
G_CALLBACK(tasks_window_closed),
286
g_signal_connect (G_OBJECT(defaultScreen), "active-window-changed",
287
G_CALLBACK(tasks_track_active_window),
292
void tasks_addNewImage(WnckWindow *window, ImagesArray* ImagesList, simSettings settings,const taskInfo& ti)
294
if (!window || !ImagesList)
296
printf("addNewImage::Null argument\n");
301
simImage *si = new simImage (ti.icon.ConvertToImage (), _T (" "), ti.name ,
302
ti.name, _T (" "), 1);
304
si->addWindow(window);
306
si->w = settings.ICONW;
307
si->h = settings.ICONH;
308
si->y = (settings.MAXSIZE + settings.BOTTOM_BORDER) - settings.ICONH - settings.BOTTOM_BORDER;
310
si->blurStatus = STATUS_NONE;
312
ImagesList->Add (si);
313
wxGetApp ().reposition ();
314
wxGetApp ().updateSize ();
318
tasks_fillList (ImagesArray * ImagesList, simSettings settings)
320
WnckScreen *defaultScreen = wnck_screen_get_default ();
321
wnck_screen_force_update (defaultScreen);
322
GList *windowz = wnck_screen_get_windows (defaultScreen);
324
WnckWindow *curr_Win=NULL;
325
int l = g_list_length (windowz);
327
//printf ("%d windows found\n", l);
329
for (int i = 0; i < l; i++)
331
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
332
if (!curr_Win || wnck_window_is_skip_tasklist (curr_Win))
337
bool init_ok = ti.Init(curr_Win);
342
for (i = 0; i < ImagesList->GetCount (); i++)
344
simImage *img = (*ImagesList)[i];
345
if (ti.compareWith (img))
347
img->addWindow(curr_Win);
352
if (i == ImagesList->GetCount())
354
tasks_addNewImage(curr_Win, ImagesList, settings, ti);
359
tasks_addNewImage(curr_Win, ImagesList, settings, ti);
367
tasks_getFromName (const char *name, int nameLength)
373
WnckScreen *defaultScreen = wnck_screen_get_default ();
374
wnck_screen_force_update (defaultScreen);
375
GList *windowz = wnck_screen_get_windows (defaultScreen);
377
WnckWindow *curr_Win;
378
int l = g_list_length (windowz);
380
for (int i = 0; i < l; i++)
382
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
383
WnckApplication *app = wnck_window_get_application (curr_Win);
384
if (strncmp (name, wnck_application_get_name (app), nameLength) == 0)
385
return wnck_window_get_xid (curr_Win);
393
tasks_getFromWindowName (const char *name, int nameLength)
399
WnckScreen *defaultScreen = wnck_screen_get_default ();
400
wnck_screen_force_update (defaultScreen);
401
GList *windowz = wnck_screen_get_windows (defaultScreen);
403
WnckWindow *curr_Win;
404
int l = g_list_length (windowz);
406
for (int i = 0; i < l; i++)
408
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
409
printf("%s \n", wnck_window_get_name (curr_Win));
410
if (strncmp (name, wnck_window_get_name (curr_Win), nameLength) == 0)
411
return wnck_window_get_xid (curr_Win);
418
void tasks_raise (WnckWindow* win)
423
if (wnck_window_is_minimized(win))
425
wnck_window_unminimize(win, gtk_get_current_event_time());
427
wnck_window_activate(win, gtk_get_current_event_time());
430
void tasks_minimize (WnckWindow* win)
223
for (unsigned int i = 0; i < ImagesList->GetCount (); i++) {
224
simImage *img = (*ImagesList)[i];
225
img->active = img->hasWindow(window);
230
void tasks_register_signals(ImagesArray * ImagesList,simSettings settings) {
231
callbackArgs* ca = new callbackArgs();
232
ca->ImagesList = ImagesList;
233
ca->settings = settings;
235
WnckScreen *defaultScreen = wnck_screen_get_default ();
236
g_signal_connect (G_OBJECT(defaultScreen), "window_opened",
237
G_CALLBACK (tasks_window_opened),
240
g_signal_connect (G_OBJECT(defaultScreen), "background-changed",
241
G_CALLBACK (tasks_window_background_change),
244
g_signal_connect (G_OBJECT(defaultScreen), "window_closed",
245
G_CALLBACK(tasks_window_closed),
248
g_signal_connect (G_OBJECT(defaultScreen), "active-window-changed",
249
G_CALLBACK(tasks_track_active_window),
254
void tasks_addNewImage(WnckWindow *window, ImagesArray* ImagesList, simSettings settings,const taskInfo& ti) {
255
if (!window || !ImagesList) {
256
printf("addNewImage::Null argument\n");
261
simImage *si = new simImage (ti.icon.ConvertToImage (), _T (" "), ti.name, ti.name, _T (" "), 1);
263
si->addWindow(window);
265
si->w = settings.ICONW;
266
si->h = settings.ICONH;
267
si->y = (settings.MAXSIZE + settings.BOTTOM_BORDER) - settings.ICONH - settings.BOTTOM_BORDER;
269
si->blurStatus = STATUS_NONE;
272
wxGetApp().frame->appSize = FirstPosition(settings, ImagesList);
273
wxGetApp().updateSize();
274
wxGetApp().refresh();
277
void tasks_fillList (ImagesArray * ImagesList, simSettings settings) {
278
WnckScreen *defaultScreen = wnck_screen_get_default ();
279
wnck_screen_force_update (defaultScreen);
280
GList *windowz = wnck_screen_get_windows (defaultScreen);
282
WnckWindow *curr_Win=NULL;
283
int l = g_list_length (windowz);
285
//printf ("%d windows found\n", l);
287
for (int i = 0; i < l; i++) {
288
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
289
if (!curr_Win || wnck_window_is_skip_tasklist (curr_Win)) {
294
bool init_ok = ti.Init(curr_Win);
298
for (i = 0; i < ImagesList->GetCount (); i++) {
299
simImage *img = (*ImagesList)[i];
300
if (ti.compareWith (img)) {
301
img->addWindow(curr_Win);
306
if (i == ImagesList->GetCount()) {
307
tasks_addNewImage(curr_Win, ImagesList, settings, ti);
310
tasks_addNewImage(curr_Win, ImagesList, settings, ti);
316
Window tasks_getFromName (const char *name, int nameLength) {
322
WnckScreen *defaultScreen = wnck_screen_get_default ();
323
wnck_screen_force_update (defaultScreen);
324
GList *windowz = wnck_screen_get_windows (defaultScreen);
326
WnckWindow *curr_Win;
327
int l = g_list_length (windowz);
329
for (int i = 0; i < l; i++) {
330
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
331
WnckApplication *app = wnck_window_get_application (curr_Win);
332
if (strncmp (name, wnck_application_get_name (app), nameLength) == 0) {
333
return wnck_window_get_xid (curr_Win);
339
Window tasks_getFromWindowName (const char *name, int nameLength) {
345
WnckScreen *defaultScreen = wnck_screen_get_default ();
346
wnck_screen_force_update (defaultScreen);
347
GList *windowz = wnck_screen_get_windows (defaultScreen);
349
WnckWindow *curr_Win;
350
int l = g_list_length (windowz);
352
for (int i = 0; i < l; i++) {
353
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
354
printf("%s \n", wnck_window_get_name (curr_Win));
355
if (strncmp (name, wnck_window_get_name (curr_Win), nameLength) == 0) {
356
return wnck_window_get_xid (curr_Win);
362
void tasks_raise (WnckWindow* win) {
367
wnck_window_unminimize(win, gtk_get_current_event_time());
368
wnck_window_activate(win, gtk_get_current_event_time());
371
void tasks_minimize (WnckWindow* win) {
435
375
wnck_window_minimize(win);