static GdkPixbuf * get_desktop_pixbuf (PanelBackground *background) { GdkPixbuf *desktop; if (!background->monitor) { background->monitor = panel_background_monitor_get_for_screen ( gdk_window_get_screen (background->window)); background->monitor_signal = g_signal_connect ( background->monitor, "changed", G_CALLBACK (background_changed), background); } g_signal_connect(gdk_window_get_screen(background->window), "composited-changed", G_CALLBACK(_panel_background_transparency), background); desktop = panel_background_monitor_get_region ( background->monitor, background->region.x, background->region.y, background->region.width, background->region.height); return desktop; }
static void camo_engine_render_background (GtkThemingEngine *engine, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { GdkRGBA color; GtkStateFlags flags = gtk_theming_engine_get_state (engine); gboolean generate = FALSE; gint scr_width, scr_height; gtk_theming_engine_get_background_color (engine, flags, &color); cairo_save (cr); if ((color.red == 0) && (color.green == 0) && (color.blue == 0)) { if (width > pool_width) { generate = TRUE; pool_width = width; } if (height > pool_height) { generate = TRUE; pool_height = height; } if (generate) { scr_width = gdk_screen_get_width (gdk_window_get_screen (gdk_get_default_root_window ())); scr_height = gdk_screen_get_height (gdk_window_get_screen (gdk_get_default_root_window ())); if (scr_width > pool_width) pool_width = scr_width; if (scr_height > pool_height) pool_height = scr_height; pool_gen (); } cairo_set_source_surface (cr, pool, 0, 0); } else gdk_cairo_set_source_rgba (cr, &color); cairo_rectangle (cr, x, y, width, height); cairo_fill (cr); cairo_restore (cr); }
void csd_locate_pointer (GdkScreen *screen) { if (!data) data = csd_locate_pointer_data_new (screen); csd_timeline_pause (data->timeline); csd_timeline_rewind (data->timeline); /* Create again the window if it is not for the current screen */ if (gdk_screen_get_number (screen) != gdk_screen_get_number (gdk_window_get_screen (data->window))) { gdk_window_set_user_data (data->window, NULL); gdk_window_destroy (data->window); create_window (data, screen); } data->progress = 0.; g_signal_connect (data->widget, "composited-changed", G_CALLBACK (composited_changed), data); move_locate_pointer_window (data, screen); composited_changed (data->widget, data); gdk_window_show (data->window); gtk_widget_show (data->widget); csd_timeline_start (data->timeline); }
static void timeline_frame_cb (CsdTimeline *timeline, gdouble progress, gpointer user_data) { CsdLocatePointerData *data = (CsdLocatePointerData *) user_data; GdkScreen *screen; gint cursor_x, cursor_y; if (gtk_widget_is_composited (data->widget)) { gdk_window_invalidate_rect (data->window, NULL, FALSE); data->progress = progress; } else if (progress >= data->progress + CIRCLES_PROGRESS_INTERVAL) { /* only invalidate window each circle interval */ update_shape (data); gdk_window_invalidate_rect (data->window, NULL, FALSE); data->progress += CIRCLES_PROGRESS_INTERVAL; } screen = gdk_window_get_screen (data->window); gdk_window_get_pointer (gdk_screen_get_root_window (screen), &cursor_x, &cursor_y, NULL); gdk_window_move (data->window, cursor_x - WINDOW_SIZE / 2, cursor_y - WINDOW_SIZE / 2); }
/* When there are multiple monitors with different resolutions, the visible area * within the root window may not be rectangular (it may have an L-shape, for * example). In that case, mask out the areas of the root window which would * not be visible in the monitors, so that screenshot do not end up with content * that the user won't ever see. */ static void mask_monitors (GdkPixbuf *pixbuf, GdkWindow *root_window) { GdkScreen *screen; cairo_region_t *region_with_monitors; cairo_region_t *invisible_region; cairo_rectangle_int_t rect; screen = gdk_window_get_screen (root_window); region_with_monitors = make_region_with_monitors (screen); rect.x = 0; rect.y = 0; rect.width = gdk_screen_get_width (screen); rect.height = gdk_screen_get_height (screen); invisible_region = cairo_region_create_rectangle (&rect); cairo_region_subtract (invisible_region, region_with_monitors); blank_region_in_pixbuf (pixbuf, invisible_region); cairo_region_destroy (region_with_monitors); cairo_region_destroy (invisible_region); }
static void get_im (GtkIMContextGCIN *context_xim) { GdkWindow *client_window = context_xim->client_window; GdkScreen *screen = gdk_window_get_screen (client_window); GdkDisplay *display = gdk_screen_get_display (screen); if (!context_xim->gcin_ch) { if (!(context_xim->gcin_ch = gcin_im_client_open(GDK_DISPLAY_XDISPLAY(gdk_display_get_default())))) perror("cannot open gcin_ch"); #if 1 context_xim->timeout_handle = 0; context_xim->pe_attN = 0; context_xim->pe_att = NULL; context_xim->pe_str = NULL; context_xim->pe_cursor = 0; #endif #if 0 // coredump g_signal_connect (display, "closed", G_CALLBACK (gcin_display_closed), context_xim); #endif if (context_xim->is_mozilla) { int rflag; gcin_im_client_set_flags(context_xim->gcin_ch, FLAG_GCIN_client_handle_raise_window, &rflag); context_xim->dirty_fix_off = (rflag & FLAG_GCIN_srv_ret_status_use_pop_up) > 0; } } }
gboolean _gdk_x11_window_simulate_button (GdkWindow *window, gint x, gint y, guint button, /*1..3*/ GdkModifierType modifiers, GdkEventType button_pressrelease) { GdkScreen *screen; XButtonEvent xev = { 0, /* type */ 0, /* serial */ 1, /* send_event */ }; gboolean success; g_return_val_if_fail (button_pressrelease == GDK_BUTTON_PRESS || button_pressrelease == GDK_BUTTON_RELEASE, FALSE); g_return_val_if_fail (window != NULL, FALSE); if (!GDK_WINDOW_IS_MAPPED (window)) return FALSE; screen = gdk_window_get_screen (window); if (x < 0 && y < 0) { x = window->width / 2; y = window->height / 2; } /* Convert to impl coordinates */ x = x + window->abs_x; y = y + window->abs_y; xev.type = button_pressrelease == GDK_BUTTON_PRESS ? ButtonPress : ButtonRelease; xev.display = GDK_WINDOW_XDISPLAY (window); xev.window = GDK_WINDOW_XID (window); xev.root = RootWindow (xev.display, GDK_X11_SCREEN (screen)->screen_num); xev.subwindow = 0; xev.time = 0; xev.x = x; xev.y = y; xev.x_root = 0; xev.y_root = 0; xev.state = modifiers; xev.button = button; gdk_x11_display_error_trap_push (GDK_WINDOW_DISPLAY (window)); xev.same_screen = XTranslateCoordinates (xev.display, xev.window, xev.root, xev.x, xev.y, &xev.x_root, &xev.y_root, &xev.subwindow); if (!xev.subwindow) xev.subwindow = xev.window; success = xev.same_screen; success &= 0 != XWarpPointer (xev.display, None, xev.window, 0, 0, 0, 0, xev.x, xev.y); success &= 0 != XSendEvent (xev.display, xev.window, True, button_pressrelease == GDK_BUTTON_PRESS ? ButtonPressMask : ButtonReleaseMask, (XEvent*) &xev); XSync (xev.display, False); success &= 0 == gdk_x11_display_error_trap_pop(GDK_WINDOW_DISPLAY (window)); return success; }
void tomboy_window_move_to_current_workspace (GtkWindow *window) { #ifndef GDK_WINDOWING_X11 return; #else GdkWindow *gdkwin = gtk_widget_get_window(GTK_WIDGET (window)); GdkWindow *rootwin = gdk_screen_get_root_window (gdk_window_get_screen (gdkwin)); GdkAtom current_desktop = gdk_atom_intern ("_NET_CURRENT_DESKTOP", FALSE); GdkAtom wm_desktop = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE); GdkAtom out_type; gint out_format, out_length; gulong *out_val; int workspace; XEvent xev; if (!gdk_property_get (rootwin, current_desktop, _GDK_MAKE_ATOM (XA_CARDINAL), 0, G_MAXLONG, FALSE, &out_type, &out_format, &out_length, (guchar **) &out_val)) return; workspace = *out_val; g_free (out_val); TRACE (g_print ("Setting _NET_WM_DESKTOP to: %d\n", workspace)); xev.xclient.type = ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.display = GDK_WINDOW_XDISPLAY (gdkwin); xev.xclient.window = GDK_WINDOW_XID (gdkwin); xev.xclient.message_type = gdk_x11_atom_to_xatom_for_display( gdk_window_get_display (gdkwin), wm_desktop); xev.xclient.format = 32; xev.xclient.data.l[0] = workspace; xev.xclient.data.l[1] = 0; xev.xclient.data.l[2] = 0; XSendEvent (GDK_WINDOW_XDISPLAY (rootwin), GDK_WINDOW_XID (rootwin), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); #endif }
static void on_fade_finished (GnomeBGCrossfade *fade, GdkWindow *window, gpointer user_data) { AthenaDesktopBackground *self = user_data; athena_desktop_background_ensure_realized (self); gnome_bg_set_surface_as_root (gdk_window_get_screen (window), self->details->background_surface); }
void set_desktop_background(GdkWindow *window) { Pixmap xpm = get_pixmap_prop(GDK_WINDOW_XWINDOW(window), "_XROOTPMAP_ID"); #ifdef HAVE_GTK3 if (xpm != None) { GdkScreen *screen = gdk_window_get_screen(window); Window root_return; int x, y; unsigned int width, height, bw, depth_ret; cairo_surface_t *surface = NULL; gdk_error_trap_push(); if (XGetGeometry(GDK_SCREEN_XDISPLAY(screen), xpm, &root_return, &x, &y, &width, &height, &bw, &depth_ret)) { surface = cairo_xlib_surface_create(GDK_SCREEN_XDISPLAY (screen), xpm, GDK_VISUAL_XVISUAL(gdk_screen_get_system_visual(screen)), width, height); } gdk_error_trap_pop_ignored (); cairo_pattern_t *pattern = cairo_pattern_create_for_surface(surface); gdk_window_set_background_pattern(window, pattern); cairo_surface_destroy(surface); // cairo_pattern_destroy ??? } else { GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 }; gdk_window_set_background_rgba(window, &black); } #else if (xpm != None) { GDKPIXMAP *gpm = gdk_pixmap_foreign_new(xpm); gdk_window_set_back_pixmap (window, gpm, FALSE); g_object_unref (gpm); } #endif }
static gboolean animations_are_disabled (MateBGCrossfade *fade) { GtkSettings *settings; GdkScreen *screen; gboolean are_enabled; g_assert (fade->priv->window != NULL); screen = gdk_window_get_screen(fade->priv->window); settings = gtk_settings_get_for_screen (screen); g_object_get (settings, "gtk-enable-animations", &are_enabled, NULL); return !are_enabled; }
static gboolean tooltips_enabled (GdkWindow *window) { gboolean enabled; gboolean touchscreen; GdkScreen *screen; GtkSettings *settings; screen = gdk_window_get_screen (window); settings = gtk_settings_get_for_screen (screen); g_object_get (settings, "gtk-touchscreen-mode", &touchscreen, "gtk-enable-tooltips", &enabled, NULL); return (!touchscreen && enabled); }
/* * sysmenu have to adjusts: x, y, width, height */ static void gtk_sys_menu_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkSysMenuPrivate * priv = GTK_SYS_MENU(widget)->priv; GdkRectangle rectangle; GdkScreen * screen; if (gtk_widget_get_realized (widget)) { screen = gdk_window_get_screen (priv->event_window); gdk_screen_get_monitor_geometry (screen, gdk_screen_get_primary_monitor (screen), &rectangle); priv->monitor_height = rectangle.height; priv->monitor_width = rectangle.width; priv->allocation.height = MAX (allocation->height, priv->amount * SYS_MENU_ITEM_HEIGHT + 15); if (priv->allocation.height > priv->monitor_height) { priv->allocation.height = priv->monitor_height - SYS_MENU_BOTTOM_Y; priv->exceed = TRUE; } priv->allocation.y = priv->monitor_height - priv->allocation.height - SYS_MENU_BOTTOM_Y; if (priv->exceed) { priv->allocation.y += 5; priv->allocation.height -= 5; } if (allocation->x + priv->allocation.width > priv->monitor_width && allocation->x < priv->allocation.width) priv->allocation.x = allocation->x - priv->allocation.width; else priv->allocation.x = allocation->x; priv->end = priv->start + (priv->allocation.height - 15) / SYS_MENU_ITEM_HEIGHT - 1; gtk_widget_set_allocation (widget, &priv->allocation); gdk_window_move_resize (priv->event_window, priv->allocation.x, priv->allocation.y + 7, priv->allocation.width, priv->allocation.height - 15); } else { gtk_widget_set_allocation (widget, allocation); } }
void cinnamon_tray_manager_manage_stage (CinnamonTrayManager *manager, ClutterStage *stage, StWidget *theme_widget) { Window stage_xwindow; GdkWindow *stage_window; GdkDisplay *display; GdkScreen *screen; g_return_if_fail (manager->priv->stage == NULL); manager->priv->stage = g_object_ref (stage); stage_xwindow = clutter_x11_get_stage_window (stage); /* This is a pretty ugly way to get the GdkScreen for the stage; it * will normally go through the foreign_new() case with a * round-trip to the X server, it might be nicer to pass the screen * in in some way. (The Clutter/Muffin combo is currently incapable * of multi-screen operation, so alternatively we could just assume * that clutter_x11_get_default_screen() gives us the right * screen.) We assume, in any case, that we are using the default * GDK display. */ display = gdk_display_get_default(); stage_window = gdk_x11_window_lookup_for_display (display, stage_xwindow); if (stage_window) g_object_ref (stage_window); else stage_window = gdk_x11_window_foreign_new_for_display (display, stage_xwindow); screen = gdk_window_get_screen (stage_window); g_object_unref (stage_window); na_tray_manager_manage_screen (manager->priv->na_manager, screen); g_signal_connect (theme_widget, "style-changed", G_CALLBACK (cinnamon_tray_manager_style_changed), manager); cinnamon_tray_manager_style_changed (theme_widget, manager); }
void gdk_x11_window_force_focus (GdkWindow *window, guint32 timestamp) { GdkDisplay *display; g_return_if_fail (GDK_IS_WINDOW (window)); display = GDK_WINDOW_DISPLAY (window); if (GTK_CHECK_VERSION(3,0,0) && !GDK_IS_X11_DISPLAY (display)) return; if (gdk_x11_screen_supports_net_wm_hint (gdk_window_get_screen (window), gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW"))) { if (!timestamp) { GTimeVal t; g_get_current_time (&t); timestamp = t.tv_sec; } XClientMessageEvent xclient; memset (&xclient, 0, sizeof (xclient)); xclient.type = ClientMessage; xclient.window = GDK_WINDOW_XID (window); xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "_NET_ACTIVE_WINDOW"); xclient.format = 32; xclient.data.l[0] = 2; /* requestor type; we're a tool */ xclient.data.l[1] = timestamp; xclient.data.l[2] = None; /* currently active window */ xclient.data.l[3] = 0; xclient.data.l[4] = 0; XSendEvent (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XROOTWIN (window), False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient); } }
void uiWindowCenter(uiWindow *w) { gint x, y; GtkAllocation winalloc; GdkWindow *gdkwin; GdkScreen *screen; GdkRectangle workarea; gtk_widget_get_allocation(w->widget, &winalloc); gdkwin = gtk_widget_get_window(w->widget); screen = gdk_window_get_screen(gdkwin); gdk_screen_get_monitor_workarea(screen, gdk_screen_get_monitor_at_window(screen, gdkwin), &workarea); x = (workarea.width - winalloc.width) / 2; y = (workarea.height - winalloc.height) / 2; // TODO move up slightly? see what Mutter or GNOME Shell or GNOME Terminal do(es)? uiWindowSetPosition(w, x, y); }
void wxClientDisplayRect(int* x, int* y, int* width, int* height) { #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 GdkRectangle rect = { 0, 0, 672, 396 }; #else GdkRectangle rect; GdkWindow* window = gtk_widget_get_window(wxGetRootWindow()); GdkScreen* screen = gdk_window_get_screen(window); int monitor = gdk_screen_get_monitor_at_window(screen, window); gdk_screen_get_monitor_workarea(screen, monitor, &rect); #endif if (x) *x = rect.x; if (y) *y = rect.y; if (width) *width = rect.width; if (height) *height = rect.height; }
static void dma_data_view_goto_position_func (DmaDataView *view) { gint x, y; gint win_x, win_y; GdkWindow *window = gtk_widget_get_window (GTK_WIDGET (view)); GdkScreen *screen = gdk_window_get_screen (window); gint monitor_num; GdkRectangle monitor; monitor_num = gdk_screen_get_monitor_at_window (screen, window); gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); gtk_widget_realize (view->goto_window); gdk_window_get_origin (window, &win_x, &win_y); x = MAX(12, win_x + 12); y = MAX(12, win_y + 12); gtk_window_move (GTK_WINDOW (view->goto_window), x, y); }
static gboolean animations_are_disabled (MateBGCrossfade *fade) { GtkSettings *settings; GdkScreen *screen; gboolean are_enabled; g_assert (fade->priv->window != NULL); #if GTK_CHECK_VERSION(2, 24, 0) screen = gdk_window_get_screen(fade->priv->window); #else // since 2.2 screen = gdk_drawable_get_screen(GDK_DRAWABLE(fade->priv->window)); #endif settings = gtk_settings_get_for_screen (screen); g_object_get (settings, "gtk-enable-animations", &are_enabled, NULL); return !are_enabled; }
static GtkArrowType get_notification_arrow_type(GtkWidget* nw) { WindowData* windata; GdkScreen* screen; GdkRectangle monitor_geometry; int monitor; windata = g_object_get_data(G_OBJECT(nw), "windata"); screen = gdk_window_get_screen(GDK_WINDOW( gtk_widget_get_window(nw))); monitor = gdk_screen_get_monitor_at_point(screen, windata->point_x, windata->point_y); gdk_screen_get_monitor_geometry(screen, monitor, &monitor_geometry); if (windata->point_y - monitor_geometry.y + windata->height + DEFAULT_ARROW_HEIGHT > monitor_geometry.height) { return GTK_ARROW_DOWN; } else { return GTK_ARROW_UP; } }
static void handle_focus_change (GdkEventCrossing *event) { GdkToplevelX11 *toplevel; GdkX11Screen *x11_screen; gboolean focus_in, had_focus; toplevel = _gdk_x11_window_get_toplevel (event->window); x11_screen = GDK_X11_SCREEN (gdk_window_get_screen (event->window)); focus_in = (event->type == GDK_ENTER_NOTIFY); if (x11_screen->wmspec_check_window) return; if (!toplevel || event->detail == GDK_NOTIFY_INFERIOR) return; toplevel->has_pointer = focus_in; if (!event->focus || toplevel->has_focus_window) return; had_focus = HAS_FOCUS (toplevel); toplevel->has_pointer_focus = focus_in; if (HAS_FOCUS (toplevel) != had_focus) { GdkEvent *focus_event; focus_event = gdk_event_new (GDK_FOCUS_CHANGE); focus_event->focus_change.window = g_object_ref (event->window); focus_event->focus_change.send_event = FALSE; focus_event->focus_change.in = focus_in; gdk_event_set_device (focus_event, gdk_event_get_device ((GdkEvent *) event)); gdk_event_put (focus_event); gdk_event_free (focus_event); } }
static gint get_max_width (GtkSourceCompletionContainer *container) { if (gtk_widget_get_realized (GTK_WIDGET (container))) { GtkWidget *toplevel; GdkWindow *window; GdkScreen *screen; gint max_width; gint xorigin; toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container)); window = gtk_widget_get_window (toplevel); screen = gdk_window_get_screen (window); gdk_window_get_origin (window, &xorigin, NULL); max_width = gdk_screen_get_width (screen) - xorigin; return MAX (max_width, UNREALIZED_WIDTH); } return UNREALIZED_WIDTH; }
int wxSystemSettingsNative::GetMetric( wxSystemMetric index, wxWindow* win ) { GdkWindow *window = NULL; if (win) window = gtk_widget_get_window(win->GetHandle()); switch (index) { case wxSYS_BORDER_X: case wxSYS_BORDER_Y: case wxSYS_EDGE_X: case wxSYS_EDGE_Y: case wxSYS_FRAMESIZE_X: case wxSYS_FRAMESIZE_Y: if (win) { wxTopLevelWindow *tlw = wxDynamicCast(win, wxTopLevelWindow); if (!tlw) return GetBorderWidth(index, win); else if (window) { // Get the frame extents from the windowmanager. // In most cases the top extent is the titlebar, so we use the bottom extent // for the heights. int right, bottom; if (wxGetFrameExtents(window, NULL, &right, NULL, &bottom)) { switch (index) { case wxSYS_BORDER_X: case wxSYS_EDGE_X: case wxSYS_FRAMESIZE_X: return right; // width of right extent default: return bottom; // height of bottom extent } } } } return -1; // no window specified case wxSYS_CURSOR_X: case wxSYS_CURSOR_Y: return gdk_display_get_default_cursor_size( window ? gdk_window_get_display(window) : gdk_display_get_default()); case wxSYS_DCLICK_X: case wxSYS_DCLICK_Y: gint dclick_distance; g_object_get(GetSettingsForWindowScreen(window), "gtk-double-click-distance", &dclick_distance, NULL); return dclick_distance * 2; case wxSYS_DCLICK_MSEC: gint dclick; g_object_get(GetSettingsForWindowScreen(window), "gtk-double-click-time", &dclick, NULL); return dclick; case wxSYS_DRAG_X: case wxSYS_DRAG_Y: gint drag_threshold; g_object_get(GetSettingsForWindowScreen(window), "gtk-dnd-drag-threshold", &drag_threshold, NULL); // The correct thing here would be to double the value // since that is what the API wants. But the values // are much bigger under GNOME than under Windows and // just seem to much in many cases to be useful. // drag_threshold *= 2; return drag_threshold; case wxSYS_ICON_X: case wxSYS_ICON_Y: return 32; case wxSYS_SCREEN_X: if (window) return gdk_screen_get_width(gdk_window_get_screen(window)); else return gdk_screen_width(); case wxSYS_SCREEN_Y: if (window) return gdk_screen_get_height(gdk_window_get_screen(window)); else return gdk_screen_height(); case wxSYS_HSCROLL_Y: case wxSYS_VSCROLL_X: return 15; case wxSYS_CAPTION_Y: if (!window) // No realized window specified, and no implementation for that case yet. return -1; wxASSERT_MSG( wxDynamicCast(win, wxTopLevelWindow), wxT("Asking for caption height of a non toplevel window") ); // Get the height of the top windowmanager border. // This is the titlebar in most cases. The titlebar might be elsewhere, and // we could check which is the thickest wm border to decide on which side the // titlebar is, but this might lead to interesting behaviours in used code. // Reconsider when we have a way to report to the user on which side it is. { int top; if (wxGetFrameExtents(window, NULL, NULL, &top, NULL)) { return top; // top frame extent } } // Try a default approach without a window pointer, if possible // ... return -1; case wxSYS_PENWINDOWS_PRESENT: // No MS Windows for Pen computing extension available in X11 based gtk+. return 0; default: return -1; // metric is unknown } }
// helper: return the GtkSettings either for the screen the current window is // on or for the default screen if window is NULL static GtkSettings *GetSettingsForWindowScreen(GdkWindow *window) { return window ? gtk_settings_get_for_screen(gdk_window_get_screen(window)) : gtk_settings_get_default(); }
LOCAL_SYMBOL MetaWindowMenu* meta_window_menu_new (MetaFrames *frames, MetaMenuOp ops, MetaMenuOp insensitive, Window client_xwindow, unsigned long active_workspace, int n_workspaces, MetaWindowMenuFunc func, gpointer data) { int i; MetaWindowMenu *menu; /* FIXME: Modifications to 'ops' should happen in meta_window_show_menu */ if (n_workspaces < 2) ops &= ~(META_MENU_OP_STICK | META_MENU_OP_UNSTICK | META_MENU_OP_WORKSPACES); menu = g_new (MetaWindowMenu, 1); menu->frames = frames; menu->client_xwindow = client_xwindow; menu->func = func; menu->data = data; menu->ops = ops; menu->insensitive = insensitive; menu->menu = gtk_menu_new (); gtk_menu_set_screen (GTK_MENU (menu->menu), gtk_widget_get_screen (GTK_WIDGET (frames))); for (i = 0; i < (int) G_N_ELEMENTS (menuitems); i++) { MenuItem menuitem = menuitems[i]; if (ops & menuitem.op || menuitem.op == 0) { GtkWidget *mi; MenuData *md; unsigned int key; MetaVirtualModifier mods; mi = menu_item_new (&menuitem, -1); /* Set the activeness of radiobuttons. */ switch (menuitem.op) { case META_MENU_OP_STICK: gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), active_workspace == 0xFFFFFFFF); break; case META_MENU_OP_UNSTICK: gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), active_workspace != 0xFFFFFFFF); break; default: break; } if (menuitem.type == MENU_ITEM_WORKSPACE_LIST) { if (ops & META_MENU_OP_WORKSPACES) { Display *display; Window xroot; GdkScreen *screen; GdkWindow *window; GtkWidget *submenu; int j; MenuItem to_another_workspace = { 0, MENU_ITEM_NORMAL, NULL, FALSE, N_("Move to Another _Workspace") }; meta_verbose ("Creating %d-workspace menu current space %lu\n", n_workspaces, active_workspace); window = gtk_widget_get_window (GTK_WIDGET (frames)); display = GDK_WINDOW_XDISPLAY (window); screen = gdk_window_get_screen (window); xroot = GDK_WINDOW_XID (gdk_screen_get_root_window (screen)); submenu = gtk_menu_new (); g_assert (mi==NULL); mi = menu_item_new (&to_another_workspace, -1); gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), submenu); for (j = 0; j < n_workspaces; j++) { char *label; MenuData *md; unsigned int key; MetaVirtualModifier mods; MenuItem moveitem; GtkWidget *submi; meta_core_get_menu_accelerator (META_MENU_OP_WORKSPACES, j + 1, &key, &mods); label = get_workspace_name_with_accel (display, xroot, j); moveitem.type = MENU_ITEM_NORMAL; moveitem.op = META_MENU_OP_WORKSPACES; moveitem.label = label; submi = menu_item_new (&moveitem, j + 1); g_free (label); if ((active_workspace == (unsigned)j) && (ops & META_MENU_OP_UNSTICK)) gtk_widget_set_sensitive (submi, FALSE); md = g_new (MenuData, 1); md->menu = menu; md->op = META_MENU_OP_WORKSPACES; g_object_set_data (G_OBJECT (submi), "workspace", GINT_TO_POINTER (j)); g_signal_connect_data (G_OBJECT (submi), "activate", G_CALLBACK (activate_cb), md, (GClosureNotify) g_free, 0); gtk_menu_shell_append (GTK_MENU_SHELL (submenu), submi); gtk_widget_show (submi); } } else meta_verbose ("not creating workspace menu\n"); } else if (menuitem.type != MENU_ITEM_SEPARATOR) { meta_core_get_menu_accelerator (menuitems[i].op, -1, &key, &mods); if (insensitive & menuitem.op) gtk_widget_set_sensitive (mi, FALSE); md = g_new (MenuData, 1); md->menu = menu; md->op = menuitem.op; g_signal_connect_data (G_OBJECT (mi), "activate", G_CALLBACK (activate_cb), md, (GClosureNotify) g_free, 0); } if (mi) { gtk_menu_shell_append (GTK_MENU_SHELL (menu->menu), mi); gtk_widget_show (mi); } } } g_signal_connect (menu->menu, "selection_done", G_CALLBACK (menu_closed), menu); return menu; }
static void gdk_device_win32_query_state (GdkDevice *device, GdkWindow *window, GdkWindow **root_window, GdkWindow **child_window, gdouble *root_x, gdouble *root_y, gdouble *win_x, gdouble *win_y, GdkModifierType *mask) { POINT point; HWND hwnd, hwndc; hwnd = GDK_WINDOW_HWND (window); GetCursorPos (&point); if (root_x) *root_x = point.x; if (root_y) *root_y = point.y; ScreenToClient (hwnd, &point); if (win_x) *win_x = point.x; if (win_y) *win_y = point.y; if (window == _gdk_root) { if (win_x) *win_x += _gdk_offset_x; if (win_y) *win_y += _gdk_offset_y; if (root_x) *root_x += _gdk_offset_x; if (root_y) *root_y += _gdk_offset_y; } if (child_window) { hwndc = ChildWindowFromPoint (hwnd, point); if (hwndc && hwndc != hwnd) *child_window = gdk_win32_handle_table_lookup (hwndc); else *child_window = NULL; /* Direct child unknown to gdk */ } if (root_window) { GdkScreen *screen; screen = gdk_window_get_screen (window); *root_window = gdk_screen_get_root_window (screen); } if (mask) *mask = get_current_mask (); }
void add_notification_action(GtkWindow* nw, const char* text, const char* key, ActionInvokedCb cb) { WindowData* windata = g_object_get_data(G_OBJECT(nw), "windata"); GtkWidget* label; GtkWidget* button; GtkWidget* hbox; GdkPixbuf* pixbuf; char* buf; g_assert(windata != NULL); if (!gtk_widget_get_visible(windata->actions_box)) { GtkWidget* alignment; gtk_widget_show(windata->actions_box); update_content_hbox_visibility(windata); alignment = gtk_alignment_new(1, 0.5, 0, 0); gtk_widget_show(alignment); gtk_box_pack_end(GTK_BOX(windata->actions_box), alignment, FALSE, TRUE, 0); windata->pie_countdown = gtk_drawing_area_new(); gtk_widget_show(windata->pie_countdown); gtk_container_add(GTK_CONTAINER(alignment), windata->pie_countdown); gtk_widget_set_size_request(windata->pie_countdown, PIE_WIDTH, PIE_HEIGHT); g_signal_connect(G_OBJECT(windata->pie_countdown), "draw", G_CALLBACK(on_countdown_draw), windata); } button = gtk_button_new(); gtk_widget_show(button); gtk_box_pack_start(GTK_BOX(windata->actions_box), button, FALSE, FALSE, 0); gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); gtk_container_set_border_width(GTK_CONTAINER(button), 0); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6); gtk_widget_show(hbox); gtk_container_add(GTK_CONTAINER(button), hbox); /* Try to be smart and find a suitable icon. */ buf = g_strdup_printf("stock_%s", key); pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_for_screen(gdk_window_get_screen(gtk_widget_get_window(GTK_WIDGET(nw)))), buf, 16, GTK_ICON_LOOKUP_USE_BUILTIN, NULL); g_free(buf); if (pixbuf != NULL) { GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); gtk_widget_show(image); gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); gtk_widget_set_halign (image, GTK_ALIGN_CENTER); gtk_widget_set_valign (image, GTK_ALIGN_CENTER); } label = gtk_label_new(NULL); gtk_widget_show(label); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); #if GTK_CHECK_VERSION (3, 16, 0) gtk_label_set_xalign (GTK_LABEL (label), 0.0); gtk_label_set_yalign (GTK_LABEL (label), 0.5); #else gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); #endif buf = g_strdup_printf("<small>%s</small>", text); gtk_label_set_markup(GTK_LABEL(label), buf); g_free(buf); g_object_set_data(G_OBJECT(button), "_nw", nw); g_object_set_data_full(G_OBJECT(button), "_action_key", g_strdup(key), g_free); g_signal_connect(G_OBJECT(button), "button-release-event", G_CALLBACK(on_action_clicked), cb); }
static gboolean gdk_broadway_device_query_state (GdkDevice *device, GdkWindow *window, GdkWindow **root_window, GdkWindow **child_window, gint *root_x, gint *root_y, gint *win_x, gint *win_y, GdkModifierType *mask) { GdkDisplay *display; GdkBroadwayDisplay *broadway_display; GdkWindowImplBroadway *impl; guint32 serial; GdkScreen *screen; char *reply; gint device_root_x, device_root_y, device_win_x, device_win_y, id; if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE) return FALSE; display = gdk_device_get_display (device); broadway_display = GDK_BROADWAY_DISPLAY (display); if (root_window) { screen = gdk_window_get_screen (window); *root_window = gdk_screen_get_root_window (screen); } if (mask) *mask = 0; /* TODO */ if (broadway_display->output) { impl = GDK_WINDOW_IMPL_BROADWAY (window->impl); serial = broadway_output_query_pointer (broadway_display->output, impl->id); reply = _gdk_broadway_display_block_for_input (display, 'q', serial, TRUE); if (reply != NULL) { char *p; char cmd; guint32 reply_serial; p = reply; cmd = *p++; reply_serial = (guint32)strtol(p, &p, 10); p++; /* Skip , */ device_root_x = strtol(p, &p, 10); p++; /* Skip , */ device_root_y = strtol(p, &p, 10); p++; /* Skip , */ device_win_x = strtol(p, &p, 10); p++; /* Skip , */ device_win_y = strtol(p, &p, 10); p++; /* Skip , */ id = strtol(p, &p, 10); if (root_x) *root_x = device_root_x; if (root_y) *root_y = device_root_y; if (win_x) *win_x = device_win_x; if (win_y) *win_y = device_win_y; if (child_window) { if (gdk_window_get_window_type (window) == GDK_WINDOW_ROOT) *child_window = g_hash_table_lookup (broadway_display->id_ht, GINT_TO_POINTER (id)); else *child_window = window; /* No native children */ } g_free (reply); return TRUE; } } /* Fallback when unconnected */ device_root_x = broadway_display->last_x; device_root_y = broadway_display->last_y; if (root_x) *root_x = device_root_x; if (root_y) *root_y = device_root_y; if (win_x) *win_x = device_root_y - window->x; if (win_y) *win_y = device_root_y - window->y; if (child_window) { if (gdk_window_get_window_type (window) == GDK_WINDOW_ROOT) { *child_window = broadway_display->mouse_in_toplevel; if (*child_window == NULL) *child_window = window; } else { /* No native children */ *child_window = window; } } return TRUE; }
/** * shell_tray_icon_click: * @icon: a #ShellTrayIcon * @event: the #ClutterEvent triggering the fake click * * Fakes a press and release on @icon. @event must be a * %CLUTTER_BUTTON_RELEASE, %CLUTTER_KEY_PRESS or %CLUTTER_KEY_RELEASE event. * Its relevant details will be passed on to the icon, but its * coordinates will be ignored; the click is * always made on the center of @icon. */ void shell_tray_icon_click (ShellTrayIcon *icon, ClutterEvent *event) { XKeyEvent xkevent; XButtonEvent xbevent; XCrossingEvent xcevent; GdkWindow *remote_window; GdkScreen *screen; int x_root, y_root; Display *xdisplay; Window xwindow, xrootwindow; ClutterEventType event_type = clutter_event_type (event); g_return_if_fail (event_type == CLUTTER_BUTTON_RELEASE || event_type == CLUTTER_KEY_PRESS || event_type == CLUTTER_KEY_RELEASE); gdk_error_trap_push (); remote_window = gtk_socket_get_plug_window (GTK_SOCKET (icon->priv->socket)); xwindow = GDK_WINDOW_XID (remote_window); xdisplay = GDK_WINDOW_XDISPLAY (remote_window); screen = gdk_window_get_screen (remote_window); xrootwindow = GDK_WINDOW_XID (gdk_screen_get_root_window (screen)); gdk_window_get_origin (remote_window, &x_root, &y_root); /* First make the icon believe the pointer is inside it */ xcevent.type = EnterNotify; xcevent.window = xwindow; xcevent.root = xrootwindow; xcevent.subwindow = None; xcevent.time = clutter_event_get_time (event); xcevent.x = gdk_window_get_width (remote_window) / 2; xcevent.y = gdk_window_get_height (remote_window) / 2; xcevent.x_root = x_root + xcevent.x; xcevent.y_root = y_root + xcevent.y; xcevent.mode = NotifyNormal; xcevent.detail = NotifyNonlinear; xcevent.same_screen = True; XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xcevent); /* Now do the click */ if (event_type == CLUTTER_BUTTON_RELEASE) { xbevent.window = xwindow; xbevent.root = xrootwindow; xbevent.subwindow = None; xbevent.time = xcevent.time; xbevent.x = xcevent.x; xbevent.y = xcevent.y; xbevent.x_root = xcevent.x_root; xbevent.y_root = xcevent.y_root; xbevent.state = clutter_event_get_state (event); xbevent.same_screen = True; xbevent.type = ButtonPress; xbevent.button = clutter_event_get_button (event); XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xbevent); xbevent.type = ButtonRelease; XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xbevent); } else { xkevent.window = xwindow; xkevent.root = xrootwindow; xkevent.subwindow = None; xkevent.time = xcevent.time; xkevent.x = xcevent.x; xkevent.y = xcevent.y; xkevent.x_root = xcevent.x_root; xkevent.y_root = xcevent.y_root; xkevent.state = clutter_event_get_state (event); xkevent.same_screen = True; xkevent.keycode = clutter_event_get_key_code (event); xkevent.type = KeyPress; XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent); if (event_type == CLUTTER_KEY_RELEASE) { /* If the application takes a grab on KeyPress, we don't * want to send it a KeyRelease. There's no good way of * knowing whether a tray icon will take a grab, so just * assume it does, and don't send the KeyRelease. That might * make the tracking for key events messed up if it doesn't take * a grab, but the tray icon won't get key focus in normal cases, * so let's hope this isn't too damaging... */ xkevent.type = KeyRelease; XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xkevent); } } /* And move the pointer back out */ xcevent.type = LeaveNotify; XSendEvent (xdisplay, xwindow, False, 0, (XEvent *)&xcevent); gdk_error_trap_pop_ignored (); }
static void widget_realized (void) { GdkWindow * window = gtk_widget_get_window (s_widget); #ifdef GDK_WINDOWING_X11 GdkScreen * screen = gdk_window_get_screen (window); int nscreen = GDK_SCREEN_XNUMBER (screen); s_display = GDK_SCREEN_XDISPLAY (screen); s_xwindow = GDK_WINDOW_XID (window); /* Create s_context */ int attribs[] = { GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 1, GLX_DOUBLEBUFFER, GLX_DEPTH_SIZE, 1, None }; XVisualInfo * xvinfo = glXChooseVisual (s_display, nscreen, attribs); g_return_if_fail (xvinfo); /* Fix up visual/colormap */ GdkVisual * visual = gdk_x11_screen_lookup_visual (screen, xvinfo->visualid); g_return_if_fail (visual); gtk_widget_set_visual (s_widget, visual); s_context = glXCreateContext (s_display, xvinfo, 0, True); g_return_if_fail (s_context); XFree (xvinfo); glXMakeCurrent (s_display, s_xwindow, s_context); #endif #ifdef GDK_WINDOWING_WIN32 s_hwnd = GDK_WINDOW_HWND (window); s_hdc = GetDC (s_hwnd); PIXELFORMATDESCRIPTOR desc = { sizeof (PIXELFORMATDESCRIPTOR), 1, // version number (?) PFD_DRAW_TO_WINDOW | // format must support window PFD_SUPPORT_OPENGL | // format must support OpenGL PFD_DOUBLEBUFFER, // must support double buffering PFD_TYPE_RGBA, // request an RGBA format 24, // select a 8:8:8 bit color depth 0, 0, 0, 0, 0, 0, // color bits ignored (?) 0, // no alpha buffer 0, // shift bit ignored (?) 0, // no accumulation buffer 0, 0, 0, 0, // accumulation bits ignored (?) 16, // 16-bit z-buffer (depth buffer) 0, // no stencil buffer 0, // no auxiliary buffer (?) PFD_MAIN_PLANE, // main drawing layer 0, // reserved (?) 0, 0, 0 // layer masks ignored (?) }; int format = ChoosePixelFormat (s_hdc, & desc); g_return_if_fail (format != 0); SetPixelFormat (s_hdc, format, & desc); s_glrc = wglCreateContext (s_hdc); g_return_if_fail (s_glrc); wglMakeCurrent (s_hdc, s_glrc); #endif }