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));
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
41
enum { BUFFERSIZE = 1024 };
42
char processName[BUFFERSIZE];
43
/* Since X doesn't rely on pids there's not a clear way to get the
46
44
* pid associated with a window. We use 2 different ways to get the
47
45
* pid. None of them is 100% accurate. (aMSN!!!) */
49
pid = wnck_window_get_pid (window);
47
pid = wnck_window_get_pid (window);
51
WnckApplication *app = wnck_window_get_application (window);
52
pid = wnck_application_get_pid (app);
49
pid = wnck_application_get_pid( wnck_window_get_application(window) );
57
printf("Could not get pid for 0x%x\n",(unsigned int) wnck_window_get_xid (window));
53
printf("Could not get pid for 0x%x\n",(unsigned int) wnck_window_get_xid (window));
61
57
if (!tasks_getProcessName(pid, &processName[0], sizeof (processName) -1))
63
printf("Could not get process name for %d\n", pid);
67
setPath(&processName[0]);
68
setName(&processName[0]);
59
printf("Could not get process name for %d\n", pid);
63
setPath(&processName[0]);
64
setName(&processName[0]);
74
bool taskInfo::compareWith (simImage * img)
76
if (name.IsEmpty() || img->link.IsEmpty())
69
bool taskInfo::compareWith (simImage * img) {
70
if (name.IsEmpty() || img->link.IsEmpty()) {
74
if (pid == img->pid) {
87
79
wxFileName launcherFN (img->link);
88
80
wxString currLauncher = launcherFN.GetName ();
89
if (launcherFN.HasExt ())
91
currLauncher = currLauncher + _T (".") + launcherFN.GetExt ();
95
if (currLauncher.Len () > name.Len ()
96
&& currLauncher.StartsWith (name))
99
if (name.StartsWith (currLauncher))
102
if (currLauncher.CmpNoCase (name) == 0)
81
if (launcherFN.HasExt ()) {
82
currLauncher = currLauncher + _T (".") + launcherFN.GetExt ();
86
if ( (currLauncher.Len() > name.Len() && currLauncher.StartsWith(name))
87
|| name.StartsWith(currLauncher)
88
|| currLauncher.CmpNoCase(name) == 0) {
109
void taskInfo::setName (char *processName)
95
void taskInfo::setName (char *processName) {
111
96
wxString s = wxString ((const char *) processName, wxConvUTF8);
112
97
wxFileName programFN (s);
113
98
name = programFN.GetName ();
114
if (programFN.HasExt ())
99
if (programFN.HasExt ()) {
116
100
name = name + _T (".") + programFN.GetExt ();
120
void taskInfo::setPath (char *processName)
104
void taskInfo::setPath (char *processName) {
122
105
path = wxString ((const char *) processName, wxConvUTF8);
127
tasks_getProcessName (unsigned int pid, char *target_name, int size_targetname)
109
int tasks_getProcessName (unsigned int pid, char *target_name, int size_targetname) {
130
111
char dir_name[PATH_MAX];
132
sprintf (dir_name, "/proc/%d/exe", pid);
113
sprintf(dir_name, "/proc/%d/exe", pid);
134
115
/* Getting the target of the exe ie to which binary it points to */
135
target_link = readlink (dir_name, target_name, size_targetname);
116
target_link = readlink(dir_name, target_name, size_targetname);
137
118
if (target_link <= 0) {
177
154
ti.Init(img->getWindow());
178
155
img->img = ti.icon.ConvertToImage();
181
wxGetApp().frame->appSize = FirstPosition(ca->settings, ImagesList);
182
wxGetApp().updateSize();
158
wxGetApp().frame->appSize = FirstPosition(ca->settings, ImagesList);
159
wxGetApp().updateSize();
189
static void tasks_window_opened (WnckScreen *screen, WnckWindow *window, callbackArgs* ca )
191
if (!ca || !ca->ImagesList)
193
printf("tasks_window_opened NULL ARGUMENT!\n");
197
ImagesArray * ImagesList = ca->ImagesList;
198
simSettings settings = ca->settings;
200
if (wnck_window_is_skip_tasklist (window))
207
for (i = 0; i < ImagesList->GetCount (); i++)
209
simImage *img = (*ImagesList)[i];
211
if (ti.compareWith (img))
213
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);
215
187
// refresh the icon, cause sometimes the splash-screen has not
216
188
// a valid icon, but the program does
217
189
img->img = ti.icon.ConvertToImage();
222
if (i == ImagesList->GetCount())
224
tasks_addNewImage(window, ImagesList, settings, ti);
194
if (i == ImagesList->GetCount()) {
195
tasks_addNewImage(window, ImagesList, settings, ti);
228
void tasks_window_background_change (WnckScreen *screen, WnckWindow *window, callbackArgs* ca )
199
void tasks_window_background_change (WnckScreen *screen, WnckWindow *window, callbackArgs* ca) {
230
200
wxBitmap* backImage = getRootWallpaper();
231
201
wxGetApp().SetWallpaper(backImage);
234
void tasks_track_active_window (WnckScreen *screen, WnckWindow *window, callbackArgs* ca ) {
235
if (!WNCK_IS_WINDOW (window))
239
ImagesArray * ImagesList = ca->ImagesList;
244
if (wnck_window_is_skip_tasklist (window)) {
204
void tasks_track_active_window (WnckScreen *screen, WnckWindow *window, callbackArgs* ca) {
205
if (!WNCK_IS_WINDOW (window)) {
209
ImagesArray * ImagesList = ca->ImagesList;
214
if (wnck_window_is_skip_tasklist (window)) {
245
215
// note that this also catches simdock itself
250
for (i = 0; i < ImagesList->GetCount (); i++)
252
simImage *img = (*ImagesList)[i];
254
if (img->hasWindow(window))
265
void tasks_register_signals(ImagesArray * ImagesList,simSettings settings)
267
callbackArgs* ca = new callbackArgs();
268
ca->ImagesList = ImagesList;
269
ca->settings = settings;
271
WnckScreen *defaultScreen = wnck_screen_get_default ();
272
g_signal_connect (G_OBJECT(defaultScreen), "window_opened",
273
G_CALLBACK (tasks_window_opened),
276
g_signal_connect (G_OBJECT(defaultScreen), "background-changed",
277
G_CALLBACK (tasks_window_background_change),
280
g_signal_connect (G_OBJECT(defaultScreen), "window_closed",
281
G_CALLBACK(tasks_window_closed),
284
g_signal_connect (G_OBJECT(defaultScreen), "active-window-changed",
285
G_CALLBACK(tasks_track_active_window),
290
void tasks_addNewImage(WnckWindow *window, ImagesArray* ImagesList, simSettings settings,const taskInfo& ti)
292
if (!window || !ImagesList)
294
printf("addNewImage::Null argument\n");
299
simImage *si = new simImage (ti.icon.ConvertToImage (), _T (" "), ti.name ,
300
ti.name, _T (" "), 1);
302
si->addWindow(window);
304
si->w = settings.ICONW;
305
si->h = settings.ICONH;
306
si->y = (settings.MAXSIZE + settings.BOTTOM_BORDER) - settings.ICONH - settings.BOTTOM_BORDER;
308
si->blurStatus = STATUS_NONE;
310
ImagesList->Add (si);
311
wxGetApp().frame->appSize = FirstPosition(settings, ImagesList);
312
wxGetApp().updateSize();
316
tasks_fillList (ImagesArray * ImagesList, simSettings settings)
318
WnckScreen *defaultScreen = wnck_screen_get_default ();
319
wnck_screen_force_update (defaultScreen);
320
GList *windowz = wnck_screen_get_windows (defaultScreen);
322
WnckWindow *curr_Win=NULL;
323
int l = g_list_length (windowz);
325
//printf ("%d windows found\n", l);
327
for (int i = 0; i < l; i++)
329
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
330
if (!curr_Win || wnck_window_is_skip_tasklist (curr_Win))
335
bool init_ok = ti.Init(curr_Win);
340
for (i = 0; i < ImagesList->GetCount (); i++)
342
simImage *img = (*ImagesList)[i];
343
if (ti.compareWith (img))
345
img->addWindow(curr_Win);
350
if (i == ImagesList->GetCount())
352
tasks_addNewImage(curr_Win, ImagesList, settings, ti);
357
tasks_addNewImage(curr_Win, ImagesList, settings, ti);
365
tasks_getFromName (const char *name, int nameLength)
371
WnckScreen *defaultScreen = wnck_screen_get_default ();
372
wnck_screen_force_update (defaultScreen);
373
GList *windowz = wnck_screen_get_windows (defaultScreen);
375
WnckWindow *curr_Win;
376
int l = g_list_length (windowz);
378
for (int i = 0; i < l; i++)
380
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
381
WnckApplication *app = wnck_window_get_application (curr_Win);
382
if (strncmp (name, wnck_application_get_name (app), nameLength) == 0)
383
return wnck_window_get_xid (curr_Win);
391
tasks_getFromWindowName (const char *name, int nameLength)
397
WnckScreen *defaultScreen = wnck_screen_get_default ();
398
wnck_screen_force_update (defaultScreen);
399
GList *windowz = wnck_screen_get_windows (defaultScreen);
401
WnckWindow *curr_Win;
402
int l = g_list_length (windowz);
404
for (int i = 0; i < l; i++)
406
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
407
printf("%s \n", wnck_window_get_name (curr_Win));
408
if (strncmp (name, wnck_window_get_name (curr_Win), nameLength) == 0)
409
return wnck_window_get_xid (curr_Win);
416
void tasks_raise (WnckWindow* win)
421
if (wnck_window_is_minimized(win))
423
wnck_window_unminimize(win, gtk_get_current_event_time());
425
wnck_window_activate(win, gtk_get_current_event_time());
428
void tasks_minimize (WnckWindow* win)
219
for (unsigned int i = 0; i < ImagesList->GetCount (); i++) {
220
simImage *img = (*ImagesList)[i];
221
img->active = img->hasWindow(window);
226
void tasks_register_signals(ImagesArray * ImagesList,simSettings settings) {
227
callbackArgs* ca = new callbackArgs();
228
ca->ImagesList = ImagesList;
229
ca->settings = settings;
231
WnckScreen *defaultScreen = wnck_screen_get_default ();
232
g_signal_connect (G_OBJECT(defaultScreen), "window_opened",
233
G_CALLBACK (tasks_window_opened),
236
g_signal_connect (G_OBJECT(defaultScreen), "background-changed",
237
G_CALLBACK (tasks_window_background_change),
240
g_signal_connect (G_OBJECT(defaultScreen), "window_closed",
241
G_CALLBACK(tasks_window_closed),
244
g_signal_connect (G_OBJECT(defaultScreen), "active-window-changed",
245
G_CALLBACK(tasks_track_active_window),
250
void tasks_addNewImage(WnckWindow *window, ImagesArray* ImagesList, simSettings settings,const taskInfo& ti) {
251
if (!window || !ImagesList) {
252
printf("addNewImage::Null argument\n");
257
simImage *si = new simImage (ti.icon.ConvertToImage (), _T (" "), ti.name, ti.name, _T (" "), 1);
259
si->addWindow(window);
261
si->w = settings.ICONW;
262
si->h = settings.ICONH;
263
si->y = (settings.MAXSIZE + settings.BOTTOM_BORDER) - settings.ICONH - settings.BOTTOM_BORDER;
265
si->blurStatus = STATUS_NONE;
268
wxGetApp().frame->appSize = FirstPosition(settings, ImagesList);
269
wxGetApp().updateSize();
272
void tasks_fillList (ImagesArray * ImagesList, simSettings settings) {
273
WnckScreen *defaultScreen = wnck_screen_get_default ();
274
wnck_screen_force_update (defaultScreen);
275
GList *windowz = wnck_screen_get_windows (defaultScreen);
277
WnckWindow *curr_Win=NULL;
278
int l = g_list_length (windowz);
280
//printf ("%d windows found\n", l);
282
for (int i = 0; i < l; i++) {
283
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
284
if (!curr_Win || wnck_window_is_skip_tasklist (curr_Win)) {
289
bool init_ok = ti.Init(curr_Win);
293
for (i = 0; i < ImagesList->GetCount (); i++) {
294
simImage *img = (*ImagesList)[i];
295
if (ti.compareWith (img)) {
296
img->addWindow(curr_Win);
301
if (i == ImagesList->GetCount()) {
302
tasks_addNewImage(curr_Win, ImagesList, settings, ti);
305
tasks_addNewImage(curr_Win, ImagesList, settings, ti);
311
Window tasks_getFromName (const char *name, int nameLength) {
317
WnckScreen *defaultScreen = wnck_screen_get_default ();
318
wnck_screen_force_update (defaultScreen);
319
GList *windowz = wnck_screen_get_windows (defaultScreen);
321
WnckWindow *curr_Win;
322
int l = g_list_length (windowz);
324
for (int i = 0; i < l; i++) {
325
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
326
WnckApplication *app = wnck_window_get_application (curr_Win);
327
if (strncmp (name, wnck_application_get_name (app), nameLength) == 0) {
328
return wnck_window_get_xid (curr_Win);
334
Window tasks_getFromWindowName (const char *name, int nameLength) {
340
WnckScreen *defaultScreen = wnck_screen_get_default ();
341
wnck_screen_force_update (defaultScreen);
342
GList *windowz = wnck_screen_get_windows (defaultScreen);
344
WnckWindow *curr_Win;
345
int l = g_list_length (windowz);
347
for (int i = 0; i < l; i++) {
348
curr_Win = (WnckWindow *) g_list_nth_data (windowz, i);
349
printf("%s \n", wnck_window_get_name (curr_Win));
350
if (strncmp (name, wnck_window_get_name (curr_Win), nameLength) == 0) {
351
return wnck_window_get_xid (curr_Win);
357
void tasks_raise (WnckWindow* win) {
362
wnck_window_unminimize(win, gtk_get_current_event_time());
363
wnck_window_activate(win, gtk_get_current_event_time());
366
void tasks_minimize (WnckWindow* win) {
433
370
wnck_window_minimize(win);