#define WNCK_I_KNOW_THIS_IS_UNSTABLE #include #include #include "gdk/gdkx.h" static GList* m_window_list = NULL; /* private cut-n-paste functions from libwnck/xutils.c */ void _wnck_activate (Screen *screen, Window xwindow, Time timestamp); void _wnck_activate_workspace (Screen *screen, int new_active_space, Time timestamp); void _modified_wnck_window_activate (WnckWindow *window); void _modified_wnck_workspace_activate (WnckWorkspace *space, WnckWindow *window); void _wnck_activate (Screen *screen, Window xwindow, Time timestamp) { XEvent xev; Atom net_active_window_atom; /* Deviating from libwnck here because copying _wnck_atom_get sounds like * overkill. This is slightly slower, but oh well. */ net_active_window_atom = XInternAtom (gdk_display, "_NET_ACTIVE_WINDOW", FALSE); xev.xclient.type = ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.display = gdk_display; xev.xclient.window = xwindow; xev.xclient.message_type = net_active_window_atom; xev.xclient.format = 32; xev.xclient.data.l[0] = 2; xev.xclient.data.l[1] = timestamp; xev.xclient.data.l[2] = 0; xev.xclient.data.l[3] = 0; xev.xclient.data.l[4] = 0; XSendEvent (gdk_display, RootWindowOfScreen (screen), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } void _wnck_activate_workspace (Screen *screen, int new_active_space, Time timestamp) { XEvent xev; Atom net_current_desktop_atom; /* Deviating from libwnck here because copying _wnck_atom_get sounds like * overkill. This is slightly slower, but oh well. */ net_current_desktop_atom = XInternAtom (gdk_display, "_NET_CURRENT_DESKTOP", FALSE); xev.xclient.type = ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.display = gdk_display; xev.xclient.window = RootWindowOfScreen (screen); xev.xclient.message_type = net_current_desktop_atom; xev.xclient.format = 32; xev.xclient.data.l[0] = new_active_space; xev.xclient.data.l[1] = timestamp; xev.xclient.data.l[2] = 0; xev.xclient.data.l[3] = 0; xev.xclient.data.l[4] = 0; XSendEvent (gdk_display, RootWindowOfScreen (screen), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } void _modified_wnck_window_activate (WnckWindow *window) { Screen *screen; Window xid; XWindowAttributes attrs; guint32 temp=gtk_get_current_event_time(); xid = wnck_window_get_xid (window); XGetWindowAttributes(gdk_display, xid, &attrs); printf ("in window value: %d",temp); _wnck_activate (attrs.screen, xid, temp); } /* The WnckWindow is merely used to get the x screen */ void _modified_wnck_workspace_activate (WnckWorkspace *space, WnckWindow *window) { Screen *screen; Window xid; XWindowAttributes attrs; guint32 temp=gtk_get_current_event_time(); xid = wnck_window_get_xid (window); XGetWindowAttributes(gdk_display, xid, &attrs); printf ("in workspace value: %d",temp); _wnck_activate_workspace (attrs.screen, wnck_workspace_get_number (space), temp); } void refreshList() { WnckScreen *screen; #ifdef HAVE_WNCK_CLIENT_TYPE static gboolean client_type_set = FALSE; #endif #ifdef HAVE_WNCK_CLIENT_TYPE /* Register as a pager, so that the window manager treats us the * same as a taskbar (i.e. having global awareness of apps) rather * than as a normal app (i.e. primarily only knowing about and * having UI for dealing with my own windows). Doesn't matter for * most cases, but some WMs in some cases treat the two * differently. */ if (!client_type_set) { wnck_set_client_type (WNCK_CLIENT_TYPE_PAGER); client_type_set = TRUE; } #endif screen = wnck_screen_get_default (); wnck_screen_force_update (screen); m_window_list = wnck_screen_get_windows (screen); } int main (int argc, char **argv) { WnckWorkspace *workspace; gboolean bSuccess; int index = 0, a=0; bSuccess = FALSE; char* keyLabel; GList *window_list_entry; gdk_init(&argc, &argv); gtk_init(&argc, &argv); refreshList(); window_list_entry = m_window_list; while (window_list_entry != NULL) { printf ("%d %s\n", index, wnck_window_get_name(window_list_entry->data)); window_list_entry = window_list_entry->next; index++; } printf ("Enter choice: "); scanf ("%d",&index); window_list_entry = m_window_list; while (anext; a++; } workspace = wnck_window_get_workspace (window_list_entry->data); if (workspace != NULL) _modified_wnck_workspace_activate (workspace, window_list_entry->data); _modified_wnck_window_activate (window_list_entry->data); return 0; }