void meta_set_stage_input_region (MetaScreen *screen, XserverRegion region) { /* As a wayland compositor we can simply ignore all this trickery * for setting an input region on the stage for capturing events in * clutter since all input comes to us first and we get to choose * who else sees them. */ if (!meta_is_wayland_compositor ()) { MetaDisplay *display = screen->display; MetaCompositor *compositor = display->compositor; Display *xdpy = meta_display_get_xdisplay (display); Window xstage = clutter_x11_get_stage_window (CLUTTER_STAGE (compositor->stage)); XFixesSetWindowShapeRegion (xdpy, xstage, ShapeInput, 0, 0, region); /* It's generally a good heuristic that when a crossing event is generated because * we reshape the overlay, we don't want it to affect focus-follows-mouse focus - * it's not the user doing something, it's the environment changing under the user. */ meta_display_add_ignored_crossing_serial (display, XNextRequest (xdpy)); XFixesSetWindowShapeRegion (xdpy, compositor->output, ShapeInput, 0, 0, region); } }
LOCAL_SYMBOL void meta_core_lower_beneath_sibling (Display *xdisplay, Window xwindow, Window grab_window, guint32 timestamp) { XWindowChanges changes; MetaDisplay *display; MetaScreen *screen; display = meta_display_for_x_display (xdisplay); screen = meta_display_screen_for_xwindow (display, xwindow); changes.stack_mode = Below; changes.sibling = grab_window; meta_stack_tracker_record_lower_below (screen->stack_tracker, xwindow, changes.sibling, XNextRequest (screen->display->xdisplay)); meta_error_trap_push (display); XConfigureWindow (xdisplay, xwindow, CWSibling | CWStackMode, &changes); meta_error_trap_pop (display); }
void KDETrayProxy::dockWindow(Window w, Window owner) { // kdDebug() << "Docking " << w << " into " << owner << endl; docked_windows[w] = XNextRequest(qt_xdisplay()); static Atom prop = XInternAtom(qt_xdisplay(), "_XEMBED_INFO", False); long data[2] = {0, 1}; XChangeProperty(qt_xdisplay(), w, prop, prop, 32, PropModeReplace, (unsigned char *)data, 2); XSizeHints hints; hints.flags = PMinSize | PMaxSize; hints.min_width = 24; hints.max_width = 24; hints.min_height = 24; hints.max_height = 24; XSetWMNormalHints(qt_xdisplay(), w, &hints); // kxerrorhandler ? XEvent ev; memset(&ev, 0, sizeof(ev)); static Atom atom = XInternAtom(qt_xdisplay(), "_NET_SYSTEM_TRAY_OPCODE", False); ev.xclient.type = ClientMessage; ev.xclient.window = owner; ev.xclient.message_type = atom; ev.xclient.format = 32; ev.xclient.data.l[0] = qt_x_time; ev.xclient.data.l[1] = 0; // SYSTEM_TRAY_REQUEST_DOCK ev.xclient.data.l[2] = w; ev.xclient.data.l[3] = 0; // unused ev.xclient.data.l[4] = 0; // unused XSendEvent(qt_xdisplay(), owner, False, NoEventMask, &ev); }
void meta_core_lower_beneath_grab_window (Display *xdisplay, Window xwindow, guint32 timestamp) { XWindowChanges changes; MetaDisplay *display; MetaScreen *screen; MetaWindow *grab_window; display = meta_display_for_x_display (xdisplay); screen = meta_display_screen_for_xwindow (display, xwindow); grab_window = display->grab_window; if (grab_window == NULL) return; changes.stack_mode = Below; changes.sibling = grab_window->frame ? grab_window->frame->xwindow : grab_window->xwindow; meta_stack_tracker_record_lower_below (screen->stack_tracker, xwindow, changes.sibling, XNextRequest (screen->display->xdisplay)); meta_error_trap_push (display); XConfigureWindow (xdisplay, xwindow, CWSibling | CWStackMode, &changes); meta_error_trap_pop (display); }
KXErrorHandler::KXErrorHandler(bool (*handler)(int request, int error_code, unsigned long resource_id), Display *dpy) : user_handler1(handler) , user_handler2(NULL) , old_handler(XSetErrorHandler(handler_wrapper)) , first_request(XNextRequest(dpy)) , display(dpy) , was_error(false) { addHandler(); }
KXErrorHandler::KXErrorHandler(int (*handler)(Display *, XErrorEvent *), Display *dpy) : user_handler1(NULL) , user_handler2(handler) , old_handler(XSetErrorHandler(handler_wrapper)) , first_request(XNextRequest(dpy)) , display(dpy) , was_error(false) { addHandler(); }
static void do_set_stage_input_region (MetaScreen *screen, XserverRegion region) { MetaCompScreen *info = meta_screen_get_compositor_data (screen); MetaDisplay *display = meta_screen_get_display (screen); Display *xdpy = meta_display_get_xdisplay (display); Window xstage = clutter_x11_get_stage_window (CLUTTER_STAGE (info->stage)); XFixesSetWindowShapeRegion (xdpy, xstage, ShapeInput, 0, 0, region); /* It's generally a good heuristic that when a crossing event is generated because * we reshape the overlay, we don't want it to affect focus-follows-mouse focus - * it's not the user doing something, it's the environment changing under the user. */ meta_display_add_ignored_crossing_serial (display, XNextRequest (xdpy)); XFixesSetWindowShapeRegion (xdpy, info->output, ShapeInput, 0, 0, region); }
MetaStackTracker * meta_stack_tracker_new (MetaScreen *screen) { MetaStackTracker *tracker; Window ignored1, ignored2; Window *children; guint n_children; tracker = g_new0 (MetaStackTracker, 1); tracker->screen = screen; tracker->server_serial = XNextRequest (screen->display->xdisplay); XQueryTree (screen->display->xdisplay, screen->xroot, &ignored1, &ignored2, &children, &n_children); tracker->server_stack = copy_stack (children, n_children); XFree (children); tracker->queued_requests = g_queue_new (); return tracker; }
void QXlibScreen::eventDispatcher() { ulong marker = XNextRequest(mDisplay->nativeDisplay()); // int i = 0; while (XPending(mDisplay->nativeDisplay())) { XEvent event; XNextEvent(mDisplay->nativeDisplay(), &event); /* done = */ handleEvent(&event); if (event.xany.serial >= marker) { #ifdef MYX11_DEBUG qDebug() << "potential livelock averted"; #endif #if 0 if (XEventsQueued(mDisplay->nativeDisplay(), QueuedAfterFlush)) { qDebug() << " with events queued"; QTimer::singleShot(0, this, SLOT(eventDispatcher())); } #endif break; } } }
bool QEventDispatcherX11::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_D(QEventDispatcherX11); d->interrupt = false; QApplication::sendPostedEvents(); ulong marker = XNextRequest(X11->display); int nevents = 0; do { while (!d->interrupt) { XEvent event; if (!(flags & QEventLoop::ExcludeUserInputEvents) && !d->queuedUserInputEvents.isEmpty()) { // process a pending user input event event = d->queuedUserInputEvents.takeFirst(); } else if (XEventsQueued(X11->display, QueuedAlready)) { // process events from the X server XNextEvent(X11->display, &event); if (flags & QEventLoop::ExcludeUserInputEvents) { // queue user input events switch (event.type) { case ButtonPress: case ButtonRelease: case MotionNotify: case XKeyPress: case XKeyRelease: case EnterNotify: case LeaveNotify: d->queuedUserInputEvents.append(event); continue; case ClientMessage: // only keep the wm_take_focus and // _qt_scrolldone protocols, queue all other // client messages if (event.xclient.format == 32) { if (event.xclient.message_type == ATOM(WM_PROTOCOLS) && (Atom) event.xclient.data.l[0] == ATOM(WM_TAKE_FOCUS)) { break; } else if (event.xclient.message_type == ATOM(_QT_SCROLL_DONE)) { break; } } d->queuedUserInputEvents.append(event); continue; default: break; } } } else { // no event to process break; } // send through event filter if (filterEvent(&event)) continue; nevents++; if (qApp->x11ProcessEvent(&event) == 1) return true; if (event.xany.serial >= marker) { if (XEventsQueued(X11->display, QueuedAfterFlush)) flags &= ~QEventLoop::WaitForMoreEvents; goto out; } } } while (!d->interrupt && XEventsQueued(X11->display, QueuedAfterFlush)); out: if (!d->interrupt) { const uint exclude_all = QEventLoop::ExcludeSocketNotifiers | QEventLoop::X11ExcludeTimers | QEventLoop::WaitForMoreEvents; if (nevents > 0 && ((uint)flags & exclude_all) == exclude_all) { QApplication::sendPostedEvents(); return nevents > 0; } // return true if we handled events, false otherwise return QEventDispatcherUNIX::processEvents(flags) || (nevents > 0); } return nevents > 0; }
MetaTilePreview * meta_tile_preview_new (int screen_number, gboolean composited) { MetaTilePreview *preview; GdkScreen *screen; screen = gdk_display_get_screen (gdk_display_get_default (), screen_number); preview = g_new (MetaTilePreview, 1); preview->preview_window = gtk_window_new (GTK_WINDOW_POPUP); gtk_window_set_screen (GTK_WINDOW (preview->preview_window), screen); gtk_widget_set_app_paintable (preview->preview_window, TRUE); preview->preview_color = NULL; preview->tile_rect.x = preview->tile_rect.y = 0; preview->tile_rect.width = preview->tile_rect.height = 0; preview->has_alpha = composited && (gdk_screen_get_rgba_visual (screen) != NULL); if (preview->has_alpha) { GtkStyleContext *context; GtkWidgetPath *path; guchar selection_alpha = 0xFF; gtk_widget_set_visual (preview->preview_window, gdk_screen_get_rgba_visual (screen)); path = gtk_widget_path_new (); gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW); context = gtk_style_context_new (); gtk_style_context_set_path (context, path); gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND); gtk_widget_path_free (path); gtk_style_context_get (context, GTK_STATE_FLAG_SELECTED, "background-color", &preview->preview_color, NULL); /* The background-color for the .rubberband class should probably * contain the correct alpha value - unfortunately, at least for now * it doesn't. Hopefully the following workaround can be removed * when GtkIconView gets ported to GtkStyleContext. */ gtk_style_context_get_style (context, "selection-box-alpha", &selection_alpha, NULL); preview->preview_color->alpha = (double)selection_alpha / 0xFF; g_object_unref (context); } /* We make an assumption that XCreateWindow will be the first operation * when calling gtk_widget_realize() (via gdk_window_new()), or that it * is at least "close enough". */ preview->create_serial = XNextRequest (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); gtk_widget_realize (preview->preview_window); g_signal_connect (preview->preview_window, "draw", G_CALLBACK (meta_tile_preview_draw), preview); return preview; }
static void update_outputs (CoglRenderer *renderer, gboolean notify) { CoglXlibRenderer *xlib_renderer = _cogl_xlib_renderer_get_data (renderer); XRRScreenResources *resources; CoglXlibTrapState state; gboolean error = FALSE; GList *new_outputs = NULL; GList *l, *m; gboolean changed = FALSE; int i; xlib_renderer->outputs_update_serial = XNextRequest (xlib_renderer->xdpy); resources = XRRGetScreenResources (xlib_renderer->xdpy, DefaultRootWindow (xlib_renderer->xdpy)); _cogl_xlib_renderer_trap_errors (renderer, &state); for (i = 0; resources && i < resources->ncrtc && !error; i++) { XRRCrtcInfo *crtc_info = NULL; XRROutputInfo *output_info = NULL; CoglOutput *output; float refresh_rate = 0; int j; crtc_info = XRRGetCrtcInfo (xlib_renderer->xdpy, resources, resources->crtcs[i]); if (crtc_info == NULL) { error = TRUE; goto next; } if (crtc_info->mode == None) goto next; for (j = 0; j < resources->nmode; j++) { if (resources->modes[j].id == crtc_info->mode) refresh_rate = (resources->modes[j].dotClock / ((float)resources->modes[j].hTotal * resources->modes[j].vTotal)); } output_info = XRRGetOutputInfo (xlib_renderer->xdpy, resources, crtc_info->outputs[0]); if (output_info == NULL) { error = TRUE; goto next; } output = _cogl_output_new (output_info->name); output->x = crtc_info->x; output->y = crtc_info->y; output->width = crtc_info->width; output->height = crtc_info->height; if ((crtc_info->rotation & (RR_Rotate_90 | RR_Rotate_270)) != 0) { output->mm_width = output_info->mm_height; output->mm_height = output_info->mm_width; } else { output->mm_width = output_info->mm_width; output->mm_height = output_info->mm_height; } output->refresh_rate = refresh_rate; switch (output_info->subpixel_order) { case SubPixelUnknown: default: output->subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN; break; case SubPixelNone: output->subpixel_order = COGL_SUBPIXEL_ORDER_NONE; break; case SubPixelHorizontalRGB: output->subpixel_order = COGL_SUBPIXEL_ORDER_HORIZONTAL_RGB; break; case SubPixelHorizontalBGR: output->subpixel_order = COGL_SUBPIXEL_ORDER_HORIZONTAL_BGR; break; case SubPixelVerticalRGB: output->subpixel_order = COGL_SUBPIXEL_ORDER_VERTICAL_RGB; break; case SubPixelVerticalBGR: output->subpixel_order = COGL_SUBPIXEL_ORDER_VERTICAL_BGR; break; } output->subpixel_order = COGL_SUBPIXEL_ORDER_HORIZONTAL_RGB; /* Handle the effect of rotation and reflection on subpixel order (ugh) */ for (j = 0; j < 6; j++) { if ((crtc_info->rotation & (1 << j)) != 0) output->subpixel_order = subpixel_map[j][output->subpixel_order]; } new_outputs = g_list_prepend (new_outputs, output); next: if (crtc_info != NULL) XFree (crtc_info); if (output_info != NULL) XFree (output_info); } XFree (resources); if (!error) { new_outputs = g_list_sort (new_outputs, (GCompareFunc)compare_outputs); l = new_outputs; m = renderer->outputs; while (l || m) { int cmp; CoglOutput *output_l = l ? (CoglOutput *)l->data : NULL; CoglOutput *output_m = m ? (CoglOutput *)m->data : NULL; if (l && m) cmp = compare_outputs (output_l, output_m); else if (l) cmp = -1; else cmp = 1; if (cmp == 0) { GList *m_next = m->next; if (!_cogl_output_values_equal (output_l, output_m)) { renderer->outputs = g_list_remove_link (renderer->outputs, m); renderer->outputs = g_list_insert_before (renderer->outputs, m_next, output_l); cogl_object_ref (output_l); changed = TRUE; } l = l->next; m = m_next; } else if (cmp < 0) { renderer->outputs = g_list_insert_before (renderer->outputs, m, output_l); cogl_object_ref (output_l); changed = TRUE; l = l->next; } else { GList *m_next = m->next; renderer->outputs = g_list_remove_link (renderer->outputs, m); changed = TRUE; m = m_next; } } } g_list_free_full (new_outputs, (GDestroyNotify)cogl_object_unref); _cogl_xlib_renderer_untrap_errors (renderer, &state); if (changed) { const CoglWinsysVtable *winsys = renderer->winsys_vtable; if (notify) COGL_NOTE (WINSYS, "Outputs changed:"); else COGL_NOTE (WINSYS, "Outputs:"); for (l = renderer->outputs; l; l = l->next) { CoglOutput *output = l->data; const char *subpixel_string; switch (output->subpixel_order) { case COGL_SUBPIXEL_ORDER_UNKNOWN: default: subpixel_string = "unknown"; break; case COGL_SUBPIXEL_ORDER_NONE: subpixel_string = "none"; break; case COGL_SUBPIXEL_ORDER_HORIZONTAL_RGB: subpixel_string = "horizontal_rgb"; break; case COGL_SUBPIXEL_ORDER_HORIZONTAL_BGR: subpixel_string = "horizontal_bgr"; break; case COGL_SUBPIXEL_ORDER_VERTICAL_RGB: subpixel_string = "vertical_rgb"; break; case COGL_SUBPIXEL_ORDER_VERTICAL_BGR: subpixel_string = "vertical_bgr"; break; } COGL_NOTE (WINSYS, " %10s: +%d+%dx%dx%d mm=%dx%d dpi=%.1fx%.1f " "subpixel_order=%s refresh_rate=%.3f", output->name, output->x, output->y, output->width, output->height, output->mm_width, output->mm_height, output->width / (output->mm_width / 25.4), output->height / (output->mm_height / 25.4), subpixel_string, output->refresh_rate); } if (notify && winsys->renderer_outputs_changed != NULL) winsys->renderer_outputs_changed (renderer); } }
/* * Order the windows on the X server to be the same as in our structure. * We do this using XRestackWindows if we don't know the previous order, * or XConfigureWindow on a few particular windows if we do and can figure * out the minimum set of changes. After that, we set __NET_CLIENT_LIST * and __NET_CLIENT_LIST_STACKING. * * FIXME: Now that we have a good view of the stacking order on the server * with MetaStackTracker it should be possible to do a simpler and better * job of computing the minimal set of stacking requests needed. */ static void stack_sync_to_server (MetaStack *stack) { GArray *stacked; GArray *root_children_stacked; GList *tmp; GArray *all_hidden; int n_override_redirect = 0; int n_unmanaging = 0; /* Bail out if frozen */ if (stack->freeze_count > 0) return; meta_topic (META_DEBUG_STACK, "Syncing window stack to server\n"); stack_ensure_sorted (stack); /* Create stacked xwindow arrays. * Painfully, "stacked" is in bottom-to-top order for the * _NET hints, and "root_children_stacked" is in top-to-bottom * order for XRestackWindows() */ stacked = g_array_new (FALSE, FALSE, sizeof (Window)); root_children_stacked = g_array_new (FALSE, FALSE, sizeof (Window)); all_hidden = g_array_new (FALSE, FALSE, sizeof (Window)); /* The screen guard window sits above all hidden windows and acts as * a barrier to input reaching these windows. */ g_array_append_val (all_hidden, stack->screen->guard_window); meta_topic (META_DEBUG_STACK, "Top to bottom: "); meta_push_no_msg_prefix (); for (tmp = stack->sorted; tmp != NULL; tmp = tmp->next) { MetaWindow *w = tmp->data; Window top_level_window; if (w->unmanaging) { n_unmanaging ++; continue; } meta_topic (META_DEBUG_STACK, "%u:%d - %s ", w->layer, w->stack_position, w->desc); /* remember, stacked is in reverse order (bottom to top) */ if (w->override_redirect) n_override_redirect++; else g_array_prepend_val (stacked, w->xwindow); if (w->frame) top_level_window = w->frame->xwindow; else top_level_window = w->xwindow; /* We don't restack hidden windows along with the rest, though they are * reflected in the _NET hints. Hidden windows all get pushed below * the screens fullscreen guard_window. */ if (w->hidden) { g_array_append_val (all_hidden, top_level_window); continue; } /* build XRestackWindows() array from top to bottom */ g_array_append_val (root_children_stacked, top_level_window); } meta_topic (META_DEBUG_STACK, "\n"); meta_pop_no_msg_prefix (); /* All windows should be in some stacking order */ if (stacked->len != stack->windows->len - n_override_redirect - n_unmanaging) meta_bug ("%u windows stacked, %u windows exist in stack\n", stacked->len, stack->windows->len); /* Sync to server */ meta_topic (META_DEBUG_STACK, "Restacking %u windows\n", root_children_stacked->len); meta_error_trap_push (stack->screen->display); if (stack->last_root_children_stacked == NULL) { /* Just impose our stack, we don't know the previous state. * This involves a ton of circulate requests and may flicker. */ meta_topic (META_DEBUG_STACK, "Don't know last stack state, restacking everything\n"); if (root_children_stacked->len > 0) { meta_stack_tracker_record_restack_windows (stack->screen->stack_tracker, (Window *) root_children_stacked->data, root_children_stacked->len, XNextRequest (stack->screen->display->xdisplay)); XRestackWindows (stack->screen->display->xdisplay, (Window *) root_children_stacked->data, root_children_stacked->len); } } else if (root_children_stacked->len > 0) { /* Try to do minimal window moves to get the stack in order */ /* A point of note: these arrays include frames not client windows, * so if a client window has changed frame since last_root_children_stacked * was saved, then we may have inefficiency, but I don't think things * break... */ const Window *old_stack = (Window *) stack->last_root_children_stacked->data; const Window *new_stack = (Window *) root_children_stacked->data; const int old_len = stack->last_root_children_stacked->len; const int new_len = root_children_stacked->len; const Window *oldp = old_stack; const Window *newp = new_stack; const Window *old_end = old_stack + old_len; const Window *new_end = new_stack + new_len; Window last_window = None; while (oldp != old_end && newp != new_end) { if (*oldp == *newp) { /* Stacks are the same here, move on */ ++oldp; last_window = *newp; ++newp; } else if (meta_display_lookup_x_window (stack->screen->display, *oldp) == NULL) { /* *oldp is no longer known to us (probably destroyed), * so we can just skip it */ ++oldp; } else { /* Move *newp below last_window */ if (last_window == None) { meta_topic (META_DEBUG_STACK, "Using window 0x%lx as topmost (but leaving it in-place)\n", *newp); raise_window_relative_to_managed_windows (stack->screen, *newp); } else { /* This means that if last_window is dead, but not * *newp, then we fail to restack *newp; but on * unmanaging last_window, we'll fix it up. */ XWindowChanges changes; changes.sibling = last_window; changes.stack_mode = Below; meta_topic (META_DEBUG_STACK, "Placing window 0x%lx below 0x%lx\n", *newp, last_window); meta_stack_tracker_record_lower_below (stack->screen->stack_tracker, *newp, last_window, XNextRequest (stack->screen->display->xdisplay)); XConfigureWindow (stack->screen->display->xdisplay, *newp, CWSibling | CWStackMode, &changes); } last_window = *newp; ++newp; } } if (newp != new_end) { /* Restack remaining windows */ meta_topic (META_DEBUG_STACK, "Restacking remaining %d windows\n", (int) (new_end - newp)); /* We need to include an already-stacked window * in the restack call, so we get in the proper position * with respect to it. */ if (newp != new_stack) --newp; meta_stack_tracker_record_restack_windows (stack->screen->stack_tracker, (Window *) newp, new_end - newp, XNextRequest (stack->screen->display->xdisplay)); XRestackWindows (stack->screen->display->xdisplay, (Window *) newp, new_end - newp); } } /* Push hidden windows to the bottom of the stack under the guard window */ meta_stack_tracker_record_lower (stack->screen->stack_tracker, stack->screen->guard_window, XNextRequest (stack->screen->display->xdisplay)); XLowerWindow (stack->screen->display->xdisplay, stack->screen->guard_window); meta_stack_tracker_record_restack_windows (stack->screen->stack_tracker, (Window *)all_hidden->data, all_hidden->len, XNextRequest (stack->screen->display->xdisplay)); XRestackWindows (stack->screen->display->xdisplay, (Window *)all_hidden->data, all_hidden->len); g_array_free (all_hidden, TRUE); meta_error_trap_pop (stack->screen->display); /* on error, a window was destroyed; it should eventually * get removed from the stacking list when we unmanage it * and we'll fix stacking at that time. */ /* Sync _NET_CLIENT_LIST and _NET_CLIENT_LIST_STACKING */ XChangeProperty (stack->screen->display->xdisplay, stack->screen->xroot, stack->screen->display->atom__NET_CLIENT_LIST, XA_WINDOW, 32, PropModeReplace, (unsigned char *)stack->windows->data, stack->windows->len); XChangeProperty (stack->screen->display->xdisplay, stack->screen->xroot, stack->screen->display->atom__NET_CLIENT_LIST_STACKING, XA_WINDOW, 32, PropModeReplace, (unsigned char *)stacked->data, stacked->len); g_array_free (stacked, TRUE); if (stack->last_root_children_stacked) g_array_free (stack->last_root_children_stacked, TRUE); stack->last_root_children_stacked = root_children_stacked; /* That was scary... */ }
/* * This function is used to avoid raising a window above popup * menus and other such things. * * The key to the operation of this function is that we are expecting * at most one window to be added at a time. If xwindow is newly added, * then its own stack position will be too high (the frame window * is created at the top of the stack), but if we ignore xwindow, * then the *next* managed window in the stack will be a window that * we've already stacked. * * We could generalize this and remove the assumption that windows * are added one at a time by keeping an explicit ->stacked flag in * MetaWindow. * * An alternate approach would be to reverse the stacking algorithm to * work by placing each window above the others, and start by lowering * a window to the bottom (instead of the current way, which works by * placing each window below another and starting with a raise) */ static void raise_window_relative_to_managed_windows (MetaScreen *screen, Window xwindow) { Window *children; int n_children; int i; meta_stack_tracker_get_stack (screen->stack_tracker, &children, &n_children); /* Children are in order from bottom to top. We want to * find the topmost managed child, then configure * our window to be above it. */ i = n_children - 1; while (i >= 0) { if (children[i] == xwindow) { /* Do nothing. This means we're already the topmost managed * window, but it DOES NOT mean we are already just above * the topmost managed window. This is important because if * an override redirect window is up, and we map a new * managed window, the new window is probably above the old * popup by default, and we want to push it below that * popup. So keep looking for a sibling managed window * to be moved below. */ } else { MetaWindow *other = meta_display_lookup_x_window (screen->display, children[i]); if (other != NULL && !other->override_redirect && !other->unmanaging) { XWindowChanges changes; /* children[i] is the topmost managed child */ meta_topic (META_DEBUG_STACK, "Moving 0x%lx above topmost managed child window 0x%lx\n", xwindow, children[i]); changes.sibling = children[i]; changes.stack_mode = Above; meta_error_trap_push (screen->display); meta_stack_tracker_record_raise_above (screen->stack_tracker, xwindow, children[i], XNextRequest (screen->display->xdisplay)); XConfigureWindow (screen->display->xdisplay, xwindow, CWSibling | CWStackMode, &changes); meta_error_trap_pop (screen->display); break; } } --i; } if (i < 0) { /* No sibling to use, just lower ourselves to the bottom * to be sure we're below any override redirect windows. */ meta_error_trap_push (screen->display); meta_stack_tracker_record_lower (screen->stack_tracker, xwindow, XNextRequest (screen->display->xdisplay)); XLowerWindow (screen->display->xdisplay, xwindow); meta_error_trap_pop (screen->display); } }
void meta_window_ensure_frame (MetaWindow *window) { MetaFrame *frame; XSetWindowAttributes attrs; gulong create_serial; if (window->frame) return; frame = g_new (MetaFrame, 1); frame->window = window; frame->xwindow = None; frame->rect = window->rect; frame->child_x = 0; frame->child_y = 0; frame->bottom_height = 0; frame->right_width = 0; frame->current_cursor = 0; frame->is_flashing = FALSE; frame->borders_cached = FALSE; meta_verbose ("Frame geometry %d,%d %dx%d\n", frame->rect.x, frame->rect.y, frame->rect.width, frame->rect.height); frame->ui_frame = meta_ui_create_frame (window->screen->ui, window->display->xdisplay, frame->window, window->xvisual, frame->rect.x, frame->rect.y, frame->rect.width, frame->rect.height, &create_serial); frame->xwindow = frame->ui_frame->xwindow; meta_stack_tracker_record_add (window->screen->stack_tracker, frame->xwindow, create_serial); meta_verbose ("Frame for %s is 0x%lx\n", frame->window->desc, frame->xwindow); attrs.event_mask = EVENT_MASK; XChangeWindowAttributes (window->display->xdisplay, frame->xwindow, CWEventMask, &attrs); meta_display_register_x_window (window->display, &frame->xwindow, window); meta_error_trap_push (window->display); if (window->mapped) { window->mapped = FALSE; /* the reparent will unmap the window, * we don't want to take that as a withdraw */ meta_topic (META_DEBUG_WINDOW_STATE, "Incrementing unmaps_pending on %s for reparent\n", window->desc); window->unmaps_pending += 1; } meta_stack_tracker_record_remove (window->screen->stack_tracker, window->xwindow, XNextRequest (window->display->xdisplay)); XReparentWindow (window->display->xdisplay, window->xwindow, frame->xwindow, frame->child_x, frame->child_y); /* FIXME handle this error */ meta_error_trap_pop (window->display); /* stick frame to the window */ window->frame = frame; /* Now that frame->xwindow is registered with window, we can set its * style and background. */ meta_frame_update_style (frame); meta_frame_update_title (frame); meta_ui_map_frame (frame->window->screen->ui, frame->xwindow); { MetaBackend *backend = meta_get_backend (); if (META_IS_BACKEND_X11 (backend)) { Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); /* Since the backend selects for events on another connection, * make sure to sync the GTK+ connection to ensure that the * frame window has been created on the server at this point. */ XSync (window->display->xdisplay, False); unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 }; XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits }; XISelectEvents (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), frame->xwindow, &mask, 1); XISetMask (mask.mask, XI_ButtonPress); XISetMask (mask.mask, XI_ButtonRelease); XISetMask (mask.mask, XI_Motion); XISetMask (mask.mask, XI_Enter); XISetMask (mask.mask, XI_Leave); XISelectEvents (xdisplay, frame->xwindow, &mask, 1); } } /* Move keybindings to frame instead of window */ meta_window_grab_keys (window); }
void meta_window_destroy_frame (MetaWindow *window) { MetaFrame *frame; MetaFrameBorders borders; if (window->frame == NULL) return; meta_verbose ("Unframing window %s\n", window->desc); frame = window->frame; meta_frame_calc_borders (frame, &borders); meta_bell_notify_frame_destroy (frame); /* Unparent the client window; it may be destroyed, * thus the error trap. */ meta_error_trap_push (window->display); if (window->mapped) { window->mapped = FALSE; /* Keep track of unmapping it, so we * can identify a withdraw initiated * by the client. */ meta_topic (META_DEBUG_WINDOW_STATE, "Incrementing unmaps_pending on %s for reparent back to root\n", window->desc); window->unmaps_pending += 1; } meta_stack_tracker_record_add (window->screen->stack_tracker, window->xwindow, XNextRequest (window->display->xdisplay)); XReparentWindow (window->display->xdisplay, window->xwindow, window->screen->xroot, /* Using anything other than client root window coordinates * coordinates here means we'll need to ensure a configure * notify event is sent; see bug 399552. */ window->frame->rect.x + borders.invisible.left, window->frame->rect.y + borders.invisible.top); meta_error_trap_pop (window->display); meta_ui_frame_unmanage (frame->ui_frame); meta_display_unregister_x_window (window->display, frame->xwindow); window->frame = NULL; if (window->frame_bounds) { cairo_region_destroy (window->frame_bounds); window->frame_bounds = NULL; } /* Move keybindings to window instead of frame */ meta_window_grab_keys (window); g_free (frame); /* Put our state back where it should be */ meta_window_queue (window, META_QUEUE_CALC_SHOWING); meta_window_queue (window, META_QUEUE_MOVE_RESIZE); }
Window meta_ui_create_frame_window (MetaUI *ui, Display *xdisplay, Visual *xvisual, gint x, gint y, gint width, gint height, gint screen_no, gulong *create_serial) { GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay); GdkScreen *screen = gdk_display_get_screen (display, screen_no); GdkWindowAttr attrs; gint attributes_mask; GdkWindow *window; GdkVisual *visual; /* Default depth/visual handles clients with weird visuals; they can * always be children of the root depth/visual obviously, but * e.g. DRI games can't be children of a parent that has the same * visual as the client. */ if (!xvisual) visual = gdk_screen_get_system_visual (screen); else { visual = gdk_x11_screen_lookup_visual (screen, XVisualIDFromVisual (xvisual)); } attrs.title = NULL; /* frame.c is going to replace the event mask immediately, but * we still have to set it here to let GDK know what it is. */ attrs.event_mask = GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_FOCUS_CHANGE_MASK; attrs.x = x; attrs.y = y; attrs.wclass = GDK_INPUT_OUTPUT; attrs.visual = visual; attrs.window_type = GDK_WINDOW_CHILD; attrs.cursor = NULL; attrs.wmclass_name = NULL; attrs.wmclass_class = NULL; attrs.override_redirect = FALSE; attrs.width = width; attrs.height = height; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; /* We make an assumption that gdk_window_new() is going to call * XCreateWindow as it's first operation; this seems to be true currently * as long as you pass in a colormap. */ if (create_serial) *create_serial = XNextRequest (xdisplay); window = gdk_window_new (gdk_screen_get_root_window(screen), &attrs, attributes_mask); gdk_window_resize (window, width, height); meta_frames_manage_window (ui->frames, GDK_WINDOW_XID (window), window); return GDK_WINDOW_XID (window); }
static Bool XRenderHasDepths (Display *dpy) { int s; for (s = 0; s < ScreenCount (dpy); s++) { CARD32 depths = 0; CARD32 missing; Screen *scr = ScreenOfDisplay (dpy, s); int d; for (d = 0; d < scr->ndepths; d++) depths |= DEPTH_MASK(scr->depths[d].depth); missing = ~depths & REQUIRED_DEPTHS; if (missing) { DepthCheckRec dc, **dp; XErrorHandler previousHandler; /* * Ok, this is ugly. It should be sufficient at this * point to just return False, but Xinerama is broken at * this point and only advertises depths which have an * associated visual. Of course, the other depths still * work, but the only way to find out is to try them. */ dc.dpy = dpy; dc.missing = 0; dc.serial = XNextRequest (dpy); _XLockMutex(_Xglobal_lock); dc.next = depthChecks; depthChecks = &dc; _XUnlockMutex (_Xglobal_lock); /* * I suspect this is not really thread safe, but Xlib doesn't * provide a lot of options here */ previousHandler = XSetErrorHandler (XRenderDepthCheckErrorHandler); /* * Try each missing depth and see if pixmap creation succeeds */ for (d = 1; d <= 32; d++) /* don't check depth 1 == Xcursor recurses... */ if ((missing & DEPTH_MASK(d)) && d != 1) { Pixmap p; p = XCreatePixmap (dpy, RootWindow (dpy, s), 1, 1, d); XFreePixmap (dpy, p); } XSync (dpy, False); XSetErrorHandler (previousHandler); /* * Unhook from the list of depth check records */ _XLockMutex(_Xglobal_lock); for (dp = &depthChecks; *dp; dp = &(*dp)->next) { if (*dp == &dc) { *dp = dc.next; break; } } _XUnlockMutex (_Xglobal_lock); if (dc.missing) return False; } } return True; }
LOCAL_SYMBOL void meta_window_ensure_frame (MetaWindow *window) { MetaFrame *frame; XSetWindowAttributes attrs; Visual *visual; gulong create_serial; if (window->frame) return; /* See comment below for why this is required. */ meta_display_grab (window->display); frame = g_new (MetaFrame, 1); frame->window = window; frame->xwindow = None; frame->rect = window->rect; frame->child_x = 0; frame->child_y = 0; frame->bottom_height = 0; frame->right_width = 0; frame->current_cursor = 0; frame->mapped = FALSE; frame->is_flashing = FALSE; meta_verbose ("Framing window %s: visual %s default, depth %d default depth %d\n", window->desc, XVisualIDFromVisual (window->xvisual) == XVisualIDFromVisual (window->screen->default_xvisual) ? "is" : "is not", window->depth, window->screen->default_depth); meta_verbose ("Frame geometry %d,%d %dx%d\n", frame->rect.x, frame->rect.y, frame->rect.width, frame->rect.height); /* Default depth/visual handles clients with weird visuals; they can * always be children of the root depth/visual obviously, but * e.g. DRI games can't be children of a parent that has the same * visual as the client. NULL means default visual. * * We look for an ARGB visual if we can find one, otherwise use * the default of NULL. */ /* Special case for depth 32 windows (assumed to be ARGB), * we use the window's visual. Otherwise we just use the system visual. */ if (window->depth == 32) visual = window->xvisual; else visual = NULL; frame->xwindow = meta_ui_create_frame_window (window->screen->ui, window->display->xdisplay, visual, frame->rect.x, frame->rect.y, frame->rect.width, frame->rect.height, frame->window->screen->number, &create_serial); meta_stack_tracker_record_add (window->screen->stack_tracker, frame->xwindow, create_serial); meta_verbose ("Frame for %s is 0x%lx\n", frame->window->desc, frame->xwindow); attrs.event_mask = EVENT_MASK; XChangeWindowAttributes (window->display->xdisplay, frame->xwindow, CWEventMask, &attrs); meta_display_register_x_window (window->display, &frame->xwindow, window); /* Reparent the client window; it may be destroyed, * thus the error trap. We'll get a destroy notify later * and free everything. Comment in FVWM source code says * we need a server grab or the child can get its MapNotify * before we've finished reparenting and getting the decoration * window onscreen, so ensure_frame must be called with * a grab. */ meta_error_trap_push (window->display); if (window->mapped) { window->mapped = FALSE; /* the reparent will unmap the window, * we don't want to take that as a withdraw */ meta_topic (META_DEBUG_WINDOW_STATE, "Incrementing unmaps_pending on %s for reparent\n", window->desc); window->unmaps_pending += 1; } /* window was reparented to this position */ window->rect.x = 0; window->rect.y = 0; meta_stack_tracker_record_remove (window->screen->stack_tracker, window->xwindow, XNextRequest (window->display->xdisplay)); XReparentWindow (window->display->xdisplay, window->xwindow, frame->xwindow, window->rect.x, window->rect.y); /* FIXME handle this error */ meta_error_trap_pop (window->display); /* stick frame to the window */ window->frame = frame; /* Now that frame->xwindow is registered with window, we can set its * style and background. */ meta_ui_update_frame_style (window->screen->ui, frame->xwindow); meta_ui_reset_frame_bg (window->screen->ui, frame->xwindow); if (window->title) meta_ui_set_frame_title (window->screen->ui, window->frame->xwindow, window->title); /* Move keybindings to frame instead of window */ meta_window_grab_keys (window); meta_display_ungrab (window->display); }