void maprequest(XEvent *e) { dbg("maprequest(): IN\n"); XMapRequestEvent *ev = &e->xmaprequest; XWindowAttributes wa; Desktop *d = NULL; Client *c = NULL; if (!(d = get_current_desktop())) return; for (c = d->head; c; c = c->next) { if (ev->window == c->win) { XMapWindow(dpy, ev->window); return; } } addwindow(ev->window); XMapWindow(dpy, ev->window); if (views[cv_id].both_views_activated) d->tile_or_float = TILE; tile(d); focuscurrent(); XGetWindowAttributes(dpy, d->curr->win, &wa); XWarpPointer(dpy, root, ev->window, 0, 0, 0, 0, --wa.width/2, --wa.height/2); draw(); dbg("maprequest(): OUT\n"); }
long desktop(long desk) { if (!_check_init()) { return -1; } if(desk > -1) { set_current_desktop(desk); } return get_current_desktop(); }
void buttonpress(XEvent *e) { dbg("buttonpress(): IN\n"); unsigned int i; Bool client_found = False; Desktop *d = NULL; Client *c = NULL; XButtonEvent ev = e->xbutton; if (e->xbutton.state == MOD1 || e->xbutton.state == MOD4) { if (!(d = get_current_desktop())) return; for (c = d->head; c; c = c->next) { if (c->win == ev.subwindow) { d->curr = c; client_found = True; focuscurrent(); XRaiseWindow(dpy, c->win); } } if (!client_found && ev.subwindow != root) { nextview(0); if (!(d = get_current_desktop())) return; for (c = d->head; c; c = c->next) { if (c->win == ev.subwindow) { d->curr = c; focuscurrent(); XRaiseWindow(dpy, c->win); break; } } } } draw(); for (i = 0; i < LENGTH(buttons); i++) { if ((buttons[i].mask == e->xbutton.state) && (buttons[i].button == e->xbutton.button) && buttons[i].func) buttons[i].func(&(buttons[i].arg)); } dbg("buttonpress(): OUT\n"); }
void TEST_set_current_desktop() { char *routine = "TEST_set_current_desktop"; printf(testing, routine); long max = desktop_count(); if(max == 1) { return; } long before = get_current_desktop(); if(before < max) { assert(set_current_desktop(max)); sleep(1); assert(desktop_count() == get_current_desktop()); } else { assert(set_current_desktop(max -1)); assert(desktop_count() != get_current_desktop()); } set_current_desktop(before); printf(done, routine); }
int get_window_desktop(Window win) { int desktop = get_property32(win, server.atom._NET_WM_DESKTOP, XA_CARDINAL); if (desktop == ALL_DESKTOPS) return desktop; if (!server.viewports) return CLAMP(desktop, 0, server.num_desktops - 1); int x, y, w, h; get_window_coordinates(win, &x, &y, &w, &h); desktop = get_current_desktop(); // Window coordinates are relative to the current viewport, make them absolute x += server.viewports[desktop].x; y += server.viewports[desktop].y; if (x < 0 || y < 0) { int num_results; long *x_screen_size = server_get_property(server.root_win, server.atom._NET_DESKTOP_GEOMETRY, XA_CARDINAL, &num_results); if (!x_screen_size) return 0; int x_screen_width = x_screen_size[0]; int x_screen_height = x_screen_size[1]; XFree(x_screen_size); // Wrap if (x < 0) x += x_screen_width; if (y < 0) y += x_screen_height; } int best_match = -1; int match_right = 0; int match_bottom = 0; // There is an ambiguity when a window is right on the edge between viewports. // In that case, prefer the viewports which is on the right and bottom of the window's top-left corner. for (int i = 0; i < server.num_desktops; i++) { if (x >= server.viewports[i].x && x <= (server.viewports[i].x + server.viewports[i].width) && y >= server.viewports[i].y && y <= (server.viewports[i].y + server.viewports[i].height)) { int current_right = x < (server.viewports[i].x + server.viewports[i].width); int current_bottom = y < (server.viewports[i].y + server.viewports[i].height); if (best_match < 0 || (!match_right && current_right) || (!match_bottom && current_bottom)) { best_match = i; } } } if (best_match < 0) best_match = 0; // fprintf(stderr, "window %lx %s : viewport %d, (%d, %d)\n", win, get_task(win) ? get_task(win)->title : "??", // best_match+1, x, y); return best_match; }
void enternotify(XEvent *e) { dbg("enternotify(): IN\n"); if (!FOLLOW_MOUSE_FOCUS) return; Client *c = NULL; Desktop *d = NULL; Bool client_found = False; XCrossingEvent *ev = &e->xcrossing; if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) return; if (!(d = get_current_desktop())) return; for (c = d->head; c; c = c->next) { if (c->win == ev->window) { dbg("enternotify(): FOCUSCURRENT()\n"); client_found = True; d->curr = c; focuscurrent(); return; } } if (!client_found && ev->window != root) { dbg("enternotify(): NEXTVIEW()\n"); nextview(0); if (!(d = get_current_desktop())) return; for (c = d->head; c; c = c->next) { if (c->win == ev->window) { d->curr = c; focuscurrent(); return; } } } dbg("enternotify(): OUT\n"); }
XCTRL_API Bool activate_window(Display *disp, Window win, Bool switch_desk) { if (switch_desk) { long desktop = get_desktop_of_window(disp,win); if (desktop>=0) { if (desktop!=get_current_desktop(disp)) { set_current_desktop(disp, desktop); } } } client_msg(disp, win, "_NET_ACTIVE_WINDOW", 2, 0, 0, 0, 0); XSetInputFocus(disp, win, RevertToNone, CurrentTime); XMapRaised(disp, win); return True; }
gboolean desktop_entry_get_show_in (DesktopEntry *entry) { if (entry->type == DESKTOP_ENTRY_DESKTOP) { const char *current_desktop = get_current_desktop (); if (current_desktop == NULL) return TRUE; else { return ((DesktopEntryDesktop *)entry)->showin; } } return ((DesktopEntryDirectory*)entry)->showin; }
void taskbar_read_clientlist (void) { Window *win, focus_win; int num, i, rev, desk, new_desk = 0; task *list, *next; desk = get_current_desktop (); if (desk != tb.my_desktop) { new_desk = 1; tb.my_desktop = desk; } XGetInputFocus (dd, &focus_win, &rev); win = get_prop_data (root_win, atom__NET_CLIENT_LIST, XA_WINDOW, &num); if (!win) return; /* remove windows that arn't in the _NET_CLIENT_LIST anymore */ list = tb.task_list; while (list) { list->focused = (focus_win == list->win); next = list->next; if (!new_desk) for (i = num - 1; i >= 0; i--) if (list->win == win[i]) goto dontdel; del_task (list->win); dontdel: list = next; } /* add any new windows */ for (i = 0; i < num; i++) { if (!find_task (win[i])) add_task (win[i], (win[i] == focus_win)); } XFree (win); }
int get_current_workarea(RDPCLIENT * This, uint32 * x, uint32 * y, uint32 * width, uint32 * height) { int current_desktop; unsigned long nitems_return; unsigned char *prop_return; uint32 *return_words; const uint32 net_workarea_x_offset = 0; const uint32 net_workarea_y_offset = 1; const uint32 net_workarea_width_offset = 2; const uint32 net_workarea_height_offset = 3; const uint32 max_prop_length = 32 * 4; /* Max 32 desktops */ if (get_property_value (This, DefaultRootWindow(This->display), "_NET_WORKAREA", max_prop_length, &nitems_return, &prop_return, 0) < 0) return (-1); if (nitems_return % 4) { fprintf(stderr, "_NET_WORKAREA has odd length\n"); return (-1); } current_desktop = get_current_desktop(This); if (current_desktop < 0) return -1; return_words = (uint32 *) prop_return; *x = return_words[current_desktop * 4 + net_workarea_x_offset]; *y = return_words[current_desktop * 4 + net_workarea_y_offset]; *width = return_words[current_desktop * 4 + net_workarea_width_offset]; *height = return_words[current_desktop * 4 + net_workarea_height_offset]; XFree(prop_return); return (0); }
int get_current_workarea(uint32 * x, uint32 * y, uint32 * width, uint32 * height) { int current_desktop; unsigned long nitems_return; unsigned char *prop_return; long *return_words; const uint32 net_workarea_x_offset = 0; const uint32 net_workarea_y_offset = 1; const uint32 net_workarea_width_offset = 2; const uint32 net_workarea_height_offset = 3; const uint32 max_prop_length = 32 * 4; /* Max 32 desktops */ if (get_property_value (DefaultRootWindow(g_display), "_NET_WORKAREA", max_prop_length, &nitems_return, &prop_return, 0) < 0) return (-1); if (nitems_return % 4) { logger(GUI, Error, "get_current_workarea(),_NET_WORKAREA has bad length"); return (-1); } current_desktop = get_current_desktop(); if (current_desktop < 0) return -1; return_words = (long *) prop_return; *x = return_words[current_desktop * 4 + net_workarea_x_offset]; *y = return_words[current_desktop * 4 + net_workarea_y_offset]; *width = return_words[current_desktop * 4 + net_workarea_width_offset]; *height = return_words[current_desktop * 4 + net_workarea_height_offset]; XFree(prop_return); return (0); }
void configurerequest(XEvent *e) { dbg("cofigurerequest(): IN\n"); XConfigureRequestEvent *ev = &e->xconfigurerequest; XWindowChanges wc; wc.x = ev->x; wc.y = ev->y; wc.width = ev->width; wc.height = ev->height; wc.border_width = ev->border_width; wc.sibling = ev->above; wc.stack_mode = ev->detail; XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); XSync(dpy, False); Desktop *d = NULL; if (!(d = get_current_desktop())) return; d->tile_or_float = FLOAT; tile(d); dbg("cofigurerequest(): OUT\n"); }
void destroynotify(XEvent *e) { dbg("destroynotify(): IN\n"); unsigned int i = 0; Client *c = NULL; Desktop *d = NULL; XDestroyWindowEvent *ev = &e->xdestroywindow; if (!(d = get_current_desktop())) return; for (c = d->head; c; c = c->next) { if (ev->window == c->win) i++; } if (i == 0) return; if (ev->window != root) removewindow(ev->window); tile(d); focuscurrent(); draw(); dbg("destroynotify(): OUT\n"); }
int get_current_workarea(uint32 * x, uint32 * y, uint32 * width, uint32 * height) { int current_desktop; unsigned long nitems_return; uint32 *prop_return; const uint32 net_workarea_x_offset = 0; const uint32 net_workarea_y_offset = 1; const uint32 net_workarea_width_offset = 2; const uint32 net_workarea_height_offset = 3; const uint32 max_prop_length = 32 * 4; /* Max 32 desktops */ if (get_property_value("_NET_WORKAREA", max_prop_length, &nitems_return, (unsigned char **) &prop_return) < 0) return (-1); if (nitems_return % 4) { fprintf(stderr, "_NET_WORKAREA has odd length\n"); return (-1); } current_desktop = get_current_desktop(); if (current_desktop < 0) return -1; *x = prop_return[current_desktop * 4 + net_workarea_x_offset]; *y = prop_return[current_desktop * 4 + net_workarea_y_offset]; *width = prop_return[current_desktop * 4 + net_workarea_width_offset]; *height = prop_return[current_desktop * 4 + net_workarea_height_offset]; XFree(prop_return); return (0); }
static void get_work_area (GdkScreen *screen, GdkRectangle *area) { Atom workarea; Atom type; Window win; int format; gulong num; gulong leftovers; gulong max_len = 4 * 32; guchar *ret_workarea; long *workareas; int result; int disp_screen; int desktop; Display *display; display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen)); disp_screen = GDK_SCREEN_XNUMBER (screen); workarea = XInternAtom (display, "_NET_WORKAREA", True); /* Defaults in case of error */ area->x = 0; area->y = 0; area->width = gdk_screen_get_width (screen); area->height = gdk_screen_get_height (screen); if (workarea == None) return; win = XRootWindow (display, disp_screen); result = XGetWindowProperty (display, win, workarea, 0, max_len, False, AnyPropertyType, &type, &format, &num, &leftovers, &ret_workarea); if (result != Success || type == None || format == 0 || leftovers || num % 4 != 0) return; desktop = get_current_desktop (screen); workareas = (long *) ret_workarea; area->x = workareas[desktop * 4]; area->y = workareas[desktop * 4 + 1]; area->width = workareas[desktop * 4 + 2]; area->height = workareas[desktop * 4 + 3]; XFree (ret_workarea); }
void gdk_x11_screen_get_work_area (GdkScreen *screen, GdkRectangle *area) { GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); Atom workarea; Atom type; Window win; int format; gulong num; gulong leftovers; gulong max_len = 4 * 32; guchar *ret_workarea = NULL; long *workareas; int result; int disp_screen; int desktop; Display *display; display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (screen)); disp_screen = GDK_SCREEN_XNUMBER (screen); workarea = XInternAtom (display, "_NET_WORKAREA", True); /* Defaults in case of error */ area->x = 0; area->y = 0; area->width = gdk_screen_get_width (screen); area->height = gdk_screen_get_height (screen); if (!gdk_x11_screen_supports_net_wm_hint (screen, gdk_atom_intern_static_string ("_NET_WORKAREA"))) return; if (workarea == None) return; win = XRootWindow (display, disp_screen); result = XGetWindowProperty (display, win, workarea, 0, max_len, False, AnyPropertyType, &type, &format, &num, &leftovers, &ret_workarea); if (result != Success || type == None || format == 0 || leftovers || num % 4 != 0) goto out; desktop = get_current_desktop (screen); if (desktop + 1 > num / 4) /* fvwm gets this wrong */ goto out; workareas = (long *) ret_workarea; area->x = workareas[desktop * 4]; area->y = workareas[desktop * 4 + 1]; area->width = workareas[desktop * 4 + 2]; area->height = workareas[desktop * 4 + 3]; area->x /= x11_screen->window_scale; area->y /= x11_screen->window_scale; area->width /= x11_screen->window_scale; area->height /= x11_screen->window_scale; out: if (ret_workarea) XFree (ret_workarea); }
void mousemove(const Arg *arg) { dbg("mousemotion(): IN\n"); int c; int rx, ry; int xw, yh; unsigned int v; Bool left_wall, right_wall; Window w; XEvent ev; XWindowAttributes wa; Desktop *d = NULL; if (!(d = get_current_desktop())) return; if (!d->curr || !XGetWindowAttributes(dpy, d->curr->win, &wa)) return; if (arg->i == RESIZE) XWarpPointer(dpy, d->curr->win, d->curr->win, 0, 0, 0, 0, --wa.width, --wa.height); if (!XQueryPointer(dpy, root, &w, &w, &rx, &ry, &c, &c, &v) || w != d->curr->win) return; if (XGrabPointer(dpy, root, False, BUTTONMASK|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime) != GrabSuccess) return; do { XMaskEvent(dpy, BUTTONMASK|PointerMotionMask|SubstructureRedirectMask, &ev); if (ev.type == MotionNotify) { xw = ((arg->i == MOVE) ? wa.x : wa.width) + ev.xmotion.x - rx; yh = ((arg->i == MOVE) ? wa.y : wa.height) + ev.xmotion.y - ry; left_wall = (xw + wa.width + 2 * BORDER_WIDTH \ < views[cv_id].split_width_x + views[cv_id].split_width_x / 10 - SEPARATOR_WIDTH / 2); right_wall = (xw \ > views[cv_id].split_width_x - views[cv_id].split_width_x / 10 + SEPARATOR_WIDTH / 2); if (arg->i == RESIZE) { d->tile_or_float = FLOAT; XResizeWindow(dpy, d->curr->win, (xw > min_window_size) ? xw : wa.width, (yh > min_window_size) ? yh : wa.height); } else if (arg->i == MOVE && views[cv_id].curr_desk == LEFT) { d->tile_or_float = FLOAT; if (views[cv_id].left_view_activated || (!views[cv_id].left_view_activated && left_wall)) { XMoveWindow(dpy, d->curr->win, xw, yh); } else if (!views[cv_id].left_view_activated && !left_wall) { /* mouse draw window from left desktop to right */ client_to_view(0); tile_current(0); views[cv_id].curr_desk = RIGHT; if (views[cv_id].rd[views[cv_id].curr_right_id].tile_or_float == TILE) { tile_current(0); } else { maximize_current(0); } views[cv_id].curr_desk = LEFT; XUngrabPointer(dpy, CurrentTime); draw(); return; } } else if (arg->i == MOVE && views[cv_id].curr_desk == RIGHT) { d->tile_or_float = FLOAT; if (views[cv_id].right_view_activated || (!views[cv_id].right_view_activated && right_wall)) { XMoveWindow(dpy, d->curr->win, xw, yh); } else if (!views[cv_id].right_view_activated && !right_wall) { /* mouse draw window from right desktop to left */ client_to_view(0); tile_current(0); views[cv_id].curr_desk = LEFT; if (views[cv_id].ld[views[cv_id].curr_left_id].tile_or_float == TILE) { tile_current(0); } else { maximize_current(0); } views[cv_id].curr_desk = RIGHT; XUngrabPointer(dpy, CurrentTime); draw(); return; } } } else if (ev.type == MapRequest) { events[ev.type](&ev); } } while (ev.type != ButtonRelease); XUngrabPointer(dpy, CurrentTime); draw(); dbg("mousemotion(): OUT\n"); }
static gboolean key_file_get_show_in (GKeyFile *key_file) { const gchar *current_desktop; gchar **strv; gboolean show_in = TRUE; int i; gchar *exec; current_desktop = get_current_desktop (); if (!current_desktop) return TRUE; exec = g_key_file_get_string (key_file, DESKTOP_ENTRY_GROUP, "Exec", NULL); if (exec) { if (g_str_has_prefix (exec, "gnome-control-center")) { g_free (exec); return FALSE; } g_free (exec); } strv = g_key_file_get_string_list (key_file, DESKTOP_ENTRY_GROUP, "OnlyShowIn", NULL, NULL); if (strv) { show_in = FALSE; for (i = 0; strv[i]; i++) { if (!strcmp (strv[i], "GNOME") || !strcmp (strv[i], "X-Cinnamon")) { show_in = TRUE; break; } } } else { strv = g_key_file_get_string_list (key_file, DESKTOP_ENTRY_GROUP, "NotShowIn", NULL, NULL); if (strv) { show_in = TRUE; for (i = 0; strv[i]; i++) { if (!strcmp (strv[i], current_desktop)) { show_in = FALSE; } } } } g_strfreev (strv); return show_in; }
void TEST_get_current_desktop() { char *routine = "TEST_get_current_desktop"; printf(testing, routine); assert(get_current_desktop()); printf(done, routine); }
static gboolean get_work_area (MateRRLabeler *labeler, GdkRectangle *rect) { Atom workarea; Atom type; Window win; int format; gulong num; gulong leftovers; gulong max_len = 4 * 32; guchar *ret_workarea; long *workareas; int result; int disp_screen; int desktop; Display *display; display = GDK_DISPLAY_XDISPLAY (gdk_screen_get_display (labeler->priv->screen)); workarea = XInternAtom (display, "_NET_WORKAREA", True); disp_screen = GDK_SCREEN_XNUMBER (labeler->priv->screen); /* Defaults in case of error */ rect->x = 0; rect->y = 0; rect->width = gdk_screen_get_width (labeler->priv->screen); rect->height = gdk_screen_get_height (labeler->priv->screen); if (workarea == None) return FALSE; win = XRootWindow (display, disp_screen); result = XGetWindowProperty (display, win, workarea, 0, max_len, False, AnyPropertyType, &type, &format, &num, &leftovers, &ret_workarea); if (result != Success || type == None || format == 0 || leftovers || num % 4) { return FALSE; } desktop = get_current_desktop (labeler->priv->screen); workareas = (long *) ret_workarea; rect->x = workareas[desktop * 4]; rect->y = workareas[desktop * 4 + 1]; rect->width = workareas[desktop * 4 + 2]; rect->height = workareas[desktop * 4 + 3]; XFree (ret_workarea); return TRUE; }