static GdkEvent * gdk_event_source_translate_event (GdkEventSource *event_source, XEvent *xevent) { GdkEvent *event = gdk_event_new (GDK_NOTHING); GdkFilterReturn result = GDK_FILTER_CONTINUE; GdkEventTranslator *event_translator; GdkWindow *filter_window; Display *dpy; dpy = GDK_DISPLAY_XDISPLAY (event_source->display); #ifdef HAVE_XGENERICEVENTS /* Get cookie data here so it's available * to every event translator and event filter. */ if (xevent->type == GenericEvent) XGetEventData (dpy, &xevent->xcookie); #endif filter_window = gdk_event_source_get_filter_window (event_source, xevent, &event_translator); if (filter_window) event->any.window = g_object_ref (filter_window); /* Run default filters */ if (_gdk_default_filters) { /* Apply global filters */ result = gdk_event_apply_filters (xevent, event, NULL); } if (result == GDK_FILTER_CONTINUE && filter_window && filter_window->filters) { /* Apply per-window filters */ result = gdk_event_apply_filters (xevent, event, filter_window); } if (result != GDK_FILTER_CONTINUE) { #ifdef HAVE_XGENERICEVENTS if (xevent->type == GenericEvent) XFreeEventData (dpy, &xevent->xcookie); #endif if (result == GDK_FILTER_REMOVE) { gdk_event_free (event); return NULL; } else /* GDK_FILTER_TRANSLATE */ return event; } gdk_event_free (event); event = NULL; if (event_translator) { /* Event translator was gotten before in get_filter_window() */ event = _gdk_x11_event_translator_translate (event_translator, event_source->display, xevent); } else { GList *list = event_source->translators; while (list && !event) { GdkEventTranslator *translator = list->data; list = list->next; event = _gdk_x11_event_translator_translate (translator, event_source->display, xevent); } } if (event && (event->type == GDK_ENTER_NOTIFY || event->type == GDK_LEAVE_NOTIFY) && event->crossing.window != NULL) { /* Handle focusing (in the case where no window manager is running */ handle_focus_change (&event->crossing); } #ifdef HAVE_XGENERICEVENTS if (xevent->type == GenericEvent) XFreeEventData (dpy, &xevent->xcookie); #endif return event; }
gboolean update_window_decoration_size (WnckWindow *win) { decor_t *d; cairo_surface_t *surface, *buffer_surface = NULL; Picture picture; Display *xdisplay; XRenderPictFormat *format; if (win == NULL) return FALSE; d = g_object_get_data (G_OBJECT (win), "decor"); if (!d->decorated) return FALSE; xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); gdk_error_trap_push (); /* Get the correct depth for the frame window in reparenting mode, otherwise * enforce 32 */ if (d->frame_window) surface = create_native_surface_and_wrap (d->width, d->height, d->frame->style_window_rgb); else surface = create_native_surface_and_wrap (d->width, d->height, d->frame->style_window_rgba); gdk_flush (); /* Handle failure */ if (!surface || gdk_error_trap_pop ()) { if (surface) cairo_surface_destroy (surface); return FALSE; } gdk_error_trap_push (); if (d->frame_window) buffer_surface = create_surface (d->width, d->height, d->frame->style_window_rgb); else buffer_surface = create_surface (d->width, d->height, d->frame->style_window_rgba); gdk_flush (); /* Handle failure */ if (!buffer_surface || gdk_error_trap_pop ()) { if (buffer_surface) cairo_surface_destroy (buffer_surface); cairo_surface_destroy (surface); return FALSE; } /* Create XRender context */ format = get_format_for_surface (d, buffer_surface); picture = XRenderCreatePicture (xdisplay, cairo_xlib_surface_get_drawable (buffer_surface), format, 0, NULL); /* Destroy the old pixmaps and pictures */ if (d->surface) cairo_surface_destroy (d->surface); if (d->x11Pixmap) decor_post_delete_pixmap (xdisplay, wnck_window_get_xid (d->win), d->x11Pixmap); if (d->buffer_surface) cairo_surface_destroy (d->buffer_surface); if (d->picture) XRenderFreePicture (xdisplay, d->picture); if (d->cr) cairo_destroy (d->cr); /* Assign new pixmaps and pictures */ d->surface = surface; d->x11Pixmap = cairo_xlib_surface_get_drawable (d->surface); d->buffer_surface = buffer_surface; d->cr = cairo_create (surface); d->picture = picture; d->prop_xid = wnck_window_get_xid (win); update_window_decoration_name (win); /* Redraw decoration on idle */ queue_decor_draw (d); return TRUE; }
int main (int argc, char **argv) { int i; char **argv_copy; int argc_copy; const char *startup_id, *display_name, *home_dir; GdkDisplay *display; TerminalOptions *options; GError *error = NULL; char *working_directory; int ret = EXIT_SUCCESS; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, TERM_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); _terminal_debug_init (); /* Make a NULL-terminated copy since we may need it later */ argv_copy = g_new (char *, argc + 1); for (i = 0; i < argc; ++i) argv_copy [i] = argv [i]; argv_copy [i] = NULL; argc_copy = argc; startup_id = g_getenv ("DESKTOP_STARTUP_ID"); working_directory = g_get_current_dir (); /* Now change directory to $HOME so we don't prevent unmounting, e.g. if the * factory is started by caja-open-terminal. See bug #565328. * On failure back to /. */ home_dir = g_get_home_dir (); if (home_dir == NULL || chdir (home_dir) < 0) (void) chdir ("/"); options = terminal_options_parse (working_directory, NULL, startup_id, NULL, FALSE, FALSE, &argc, &argv, &error, gtk_get_option_group (TRUE), egg_sm_client_get_option_group (), NULL); g_free (working_directory); if (options == NULL) { g_printerr (_("Failed to parse arguments: %s\n"), error->message); g_error_free (error); exit (EXIT_FAILURE); } g_set_application_name (_("Terminal")); /* Unset the these env variables, so they doesn't end up * in the factory's env and thus in the terminals' envs. */ g_unsetenv ("DESKTOP_STARTUP_ID"); g_unsetenv ("GIO_LAUNCHED_DESKTOP_FILE_PID"); g_unsetenv ("GIO_LAUNCHED_DESKTOP_FILE"); display = gdk_display_get_default (); display_name = gdk_display_get_name (display); options->display_name = g_strdup (display_name); if (options->startup_id == NULL) { /* Create a fake one containing a timestamp that we can use */ Time timestamp; timestamp = slowly_and_stupidly_obtain_timestamp (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); options->startup_id = g_strdup_printf ("_TIME%lu", timestamp); } if (options->use_factory) { OwnData *data; guint owner_id; data = g_new (OwnData, 1); data->factory_name = get_factory_name_for_display (display_name); data->options = options; data->exit_code = -1; data->argv = argv_copy; data->argc = argc_copy; gtk_init(&argc, &argv); options->initial_workspace = get_initial_workspace (); owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, data->factory_name, G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired_cb, name_acquired_cb, name_lost_cb, data, NULL); gtk_main (); ret = data->exit_code; g_bus_unown_name (owner_id); g_free (data->factory_name); g_free (data); } else { terminal_app_handle_options (terminal_app_get (), options, TRUE /* allow resume */, &error); terminal_options_free (options); if (error == NULL) { gtk_main (); } else { g_printerr ("Error handling options: %s\n", error->message); g_error_free (error); ret = EXIT_FAILURE; } } terminal_app_shutdown (); g_free (argv_copy); return ret; }
static void _xim_init_IMdkit () { #if 0 XIMStyle ims_styles_overspot [] = { XIMPreeditPosition | XIMStatusNothing, XIMPreeditNothing | XIMStatusNothing, XIMPreeditPosition | XIMStatusCallbacks, XIMPreeditNothing | XIMStatusCallbacks, 0 }; #endif XIMStyle ims_styles_onspot [] = { XIMPreeditPosition | XIMStatusNothing, XIMPreeditCallbacks | XIMStatusNothing, XIMPreeditNothing | XIMStatusNothing, XIMPreeditPosition | XIMStatusCallbacks, XIMPreeditCallbacks | XIMStatusCallbacks, XIMPreeditNothing | XIMStatusCallbacks, 0 }; XIMEncoding ims_encodings[] = { "COMPOUND_TEXT", 0 }; GdkWindowAttr window_attr = { .title = "ibus-xim", .event_mask = GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK, .wclass = GDK_INPUT_OUTPUT, .window_type = GDK_WINDOW_TOPLEVEL, .override_redirect = 1, }; XIMStyles styles; XIMEncodings encodings; GdkWindow *win; win = gdk_window_new (NULL, &window_attr, GDK_WA_TITLE); styles.count_styles = sizeof (ims_styles_onspot)/sizeof (XIMStyle) - 1; styles.supported_styles = ims_styles_onspot; encodings.count_encodings = sizeof (ims_encodings)/sizeof (XIMEncoding) - 1; encodings.supported_encodings = ims_encodings; _xims = IMOpenIM(GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), IMModifiers, "Xi18n", IMServerWindow, GDK_WINDOW_XWINDOW(win), IMServerName, _server_name != NULL ? _server_name : "ibus", IMLocale, _locale != NULL ? _locale : LOCALES_STRING, IMServerTransport, "X/", IMInputStyles, &styles, IMEncodingList, &encodings, IMProtocolHandler, ims_protocol_handler, IMFilterEventMask, KeyPressMask | KeyReleaseMask, NULL); _init_ibus (); if (!ibus_bus_is_connected (_bus)) { g_warning ("Can not connect to ibus daemon"); exit (EXIT_FAILURE); } } static void _atexit_cb () { if (_bus && ibus_bus_is_connected (_bus)) { ibus_bus_exit(_bus, False); } } static void _sighandler (int sig) { exit(EXIT_FAILURE); }
static gboolean remmina_rdp_event_on_key(GtkWidget* widget, GdkEventKey* event, RemminaProtocolWidget* gp) { GdkDisplay* display; guint16 cooked_keycode; rfContext* rfi; RemminaPluginRdpEvent rdp_event; rfi = GET_DATA(gp); rdp_event.type = REMMINA_RDP_EVENT_TYPE_SCANCODE; rdp_event.key_event.up = (event->type == GDK_KEY_PRESS ? False : True); rdp_event.key_event.extended = False; switch (event->keyval) { case GDK_KEY_Pause: rdp_event.key_event.key_code = 0x1D; rdp_event.key_event.up = False; remmina_rdp_event_event_push(gp, &rdp_event); rdp_event.key_event.key_code = 0x45; rdp_event.key_event.up = False; remmina_rdp_event_event_push(gp, &rdp_event); rdp_event.key_event.key_code = 0x1D; rdp_event.key_event.up = True; remmina_rdp_event_event_push(gp, &rdp_event); rdp_event.key_event.key_code = 0x45; rdp_event.key_event.up = True; remmina_rdp_event_event_push(gp, &rdp_event); break; default: if (!rfi->use_client_keymap) { rdp_event.key_event.key_code = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(event->hardware_keycode); remmina_plugin_service->log_printf("[RDP]keyval=%04X keycode=%i scancode=%i extended=%i\n", event->keyval, event->hardware_keycode, rdp_event.key_event.key_code, &rdp_event.key_event.extended); } else { //TODO: Port to GDK functions display = gdk_display_get_default(); cooked_keycode = XKeysymToKeycode(GDK_DISPLAY_XDISPLAY(display), XKeycodeToKeysym(GDK_DISPLAY_XDISPLAY(display), event->hardware_keycode, 0)); rdp_event.key_event.key_code = freerdp_keyboard_get_rdp_scancode_from_x11_keycode(cooked_keycode); remmina_plugin_service->log_printf("[RDP]keyval=%04X raw_keycode=%i cooked_keycode=%i scancode=%i extended=%i\n", event->keyval, event->hardware_keycode, cooked_keycode, rdp_event.key_event.key_code, &rdp_event.key_event.extended); } if (rdp_event.key_event.key_code) remmina_rdp_event_event_push(gp, &rdp_event); break; } /* Register/unregister the pressed key */ if (rdp_event.key_event.key_code) { if (event->type == GDK_KEY_PRESS) g_array_append_val(rfi->pressed_keys, rdp_event.key_event.key_code); else remmina_rdp_event_release_key(gp, rdp_event.key_event.key_code); } return TRUE; }
gboolean gdk_property_get (GdkWindow *window, GdkAtom property, GdkAtom type, gulong offset, gulong length, gint pdelete, GdkAtom *actual_property_type, gint *actual_format_type, gint *actual_length, guchar **data) { GdkDisplay *display; Atom ret_prop_type; gint ret_format; gulong ret_nitems; gulong ret_bytes_after; gulong get_length; gulong ret_length; guchar *ret_data; Atom xproperty; Atom xtype; int res; g_return_val_if_fail (!window || GDK_WINDOW_IS_X11 (window), FALSE); if (!window) { GdkScreen *screen = gdk_screen_get_default (); window = gdk_screen_get_root_window (screen); GDK_NOTE (MULTIHEAD, g_message ("gdk_property_get(): window is NULL\n")); } else if (!GDK_WINDOW_IS_X11 (window)) return FALSE; if (GDK_WINDOW_DESTROYED (window)) return FALSE; display = gdk_drawable_get_display (window); xproperty = gdk_x11_atom_to_xatom_for_display (display, property); if (type == GDK_NONE) xtype = AnyPropertyType; else xtype = gdk_x11_atom_to_xatom_for_display (display, type); ret_data = NULL; /* * Round up length to next 4 byte value. Some code is in the (bad?) * habit of passing G_MAXLONG as the length argument, causing an * overflow to negative on the add. In this case, we clamp the * value to G_MAXLONG. */ get_length = length + 3; if (get_length > G_MAXLONG) get_length = G_MAXLONG; /* To fail, either the user passed 0 or G_MAXULONG */ get_length = get_length / 4; if (get_length == 0) { g_warning ("gdk_propery-get(): invalid length 0"); return FALSE; } res = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XWINDOW (window), xproperty, offset, get_length, pdelete, xtype, &ret_prop_type, &ret_format, &ret_nitems, &ret_bytes_after, &ret_data); if (res != Success || (ret_prop_type == None && ret_format == 0)) { return FALSE; } if (actual_property_type) *actual_property_type = gdk_x11_xatom_to_atom_for_display (display, ret_prop_type); if (actual_format_type) *actual_format_type = ret_format; if ((xtype != AnyPropertyType) && (ret_prop_type != xtype)) { XFree (ret_data); g_warning ("Couldn't match property type %s to %s\n", gdk_x11_get_xatom_name_for_display (display, ret_prop_type), gdk_x11_get_xatom_name_for_display (display, xtype)); return FALSE; } /* FIXME: ignoring bytes_after could have very bad effects */ if (data) { if (ret_prop_type == XA_ATOM || ret_prop_type == gdk_x11_get_xatom_by_name_for_display (display, "ATOM_PAIR")) { /* * data is an array of X atom, we need to convert it * to an array of GDK Atoms */ gint i; GdkAtom *ret_atoms = g_new (GdkAtom, ret_nitems); Atom *xatoms = (Atom *)ret_data; *data = (guchar *)ret_atoms; for (i = 0; i < ret_nitems; i++) ret_atoms[i] = gdk_x11_xatom_to_atom_for_display (display, xatoms[i]); if (actual_length) *actual_length = ret_nitems * sizeof (GdkAtom); } else { switch (ret_format) { case 8: ret_length = ret_nitems; break; case 16: ret_length = sizeof(short) * ret_nitems; break; case 32: ret_length = sizeof(long) * ret_nitems; break; default: g_warning ("unknown property return format: %d", ret_format); XFree (ret_data); return FALSE; } *data = g_new (guchar, ret_length); memcpy (*data, ret_data, ret_length); if (actual_length) *actual_length = ret_length; } } XFree (ret_data); return TRUE; }
void *wxGetDisplay() { return GDK_DISPLAY_XDISPLAY(gdk_window_get_display(wxGetTopLevelGDK())); }
int main (int argc, char **argv) { gboolean supports_xinput; gboolean has_touchpad, has_touchscreen, has_trackball; XDeviceInfo *device_info; gint n_devices, opcode; guint i; gtk_init (&argc, &argv); supports_xinput = supports_xinput_devices (); if (supports_xinput) { g_print ("Supports XInput:\t\t\tyes\n"); } else { g_print ("Supports XInput:\t\t\tno\n"); return 0; } supports_xinput = supports_xinput2_devices (&opcode); if (supports_xinput) { g_print ("Supports XInput2:\t\t\tyes (opcode: %d)\n", opcode); } else { g_print ("Supports XInput2:\t\t\tno\n"); return 0; } has_touchpad = touchpad_is_present (); g_print ("Has touchpad:\t\t\t\t%s\n", has_touchpad ? "yes" : "no"); has_touchscreen = touchscreen_is_present (); g_print ("Has touchscreen:\t\t\t%s\n", has_touchscreen ? "yes" : "no"); has_trackball = trackball_is_present (); g_print ("Has trackball:\t\t\t\t%s\n", has_trackball ? "yes" : "no"); device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &n_devices); if (device_info == NULL) { g_warning ("Has no input devices"); return 1; } print_disabled_devices (); for (i = 0; i < n_devices; i++) { XDevice *device; if (device_info_is_touchscreen (&device_info[i])) { g_print ("Device %d is touchscreen:\t\t%s\n", (int) device_info[i].id, "yes"); continue; } if (device_info_is_trackball (&device_info[i])) { g_print ("Device %d is trackball:\t\t\t%s\n", (int) device_info[i].id, "yes"); continue; } if (device_info_is_tablet (&device_info[i])) { g_print ("Device %d is tablet:\t\t\t%s\n", (int) device_info[i].id, "yes"); continue; } gdk_error_trap_push (); device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device_info[i].id); if (gdk_error_trap_pop () || (device == NULL)) continue; if (device_is_touchpad (device)) g_print ("Device %d is touchpad:\t\t%s\n", (int) device_info[i].id, "yes"); else { int tool_id; tool_id = xdevice_get_last_tool_id (device_info[i].id); if (tool_id >= 0x0) g_print ("Device %d is touchpad/touchscreen:\t%s (tool ID: 0x%x)\n", (int) device_info[i].id, "no", tool_id); else g_print ("Device %d is touchpad/touchscreen:\t%s\n", (int) device_info[i].id, "no"); } XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device); } XFreeDeviceList (device_info); return 0; }
guint egg_tray_icon_send_message (EggTrayIcon *icon, gint timeout, const gchar *message, gint len) { guint stamp; g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0); g_return_val_if_fail (timeout >= 0, 0); g_return_val_if_fail (message != NULL, 0); if (icon->manager_window == None) return 0; if (len < 0) len = strlen (message); stamp = icon->stamp++; /* Get ready to send the message */ egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE, (Window)gtk_plug_xembed_get_id (GTK_PLUG_XEMBED (icon)), timeout, len, stamp); /* Now to send the actual message */ gdk_error_trap_push (); while (len > 0) { XClientMessageEvent ev; Display *xdisplay; #if HAVE_GTK_MULTIHEAD xdisplay = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); #else xdisplay = gdk_display; #endif ev.type = ClientMessage; ev.window = (Window)gtk_plug_xembed_get_id (GTK_PLUG_XEMBED (icon)); ev.format = 8; ev.message_type = XInternAtom (xdisplay, "_NET_SYSTEM_TRAY_MESSAGE_DATA", False); if (len > 20) { memcpy (&ev.data, message, 20); len -= 20; message += 20; } else { memcpy (&ev.data, message, len); len = 0; } XSendEvent (xdisplay, icon->manager_window, False, StructureNotifyMask, (XEvent *)&ev); XSync (xdisplay, False); } gdk_error_trap_pop (); return stamp; }
nsresult nsScreenManagerGtk :: Init() { #ifdef MOZ_X11 XineramaScreenInfo *screenInfo = nullptr; int numScreens; bool useXinerama = GDK_IS_X11_DISPLAY(gdk_display_get_default()); if (useXinerama && !mXineramalib) { mXineramalib = PR_LoadLibrary("libXinerama.so.1"); if (!mXineramalib) { mXineramalib = SCREEN_MANAGER_LIBRARY_LOAD_FAILED; } } if (mXineramalib && mXineramalib != SCREEN_MANAGER_LIBRARY_LOAD_FAILED) { _XnrmIsActive_fn _XnrmIsActive = (_XnrmIsActive_fn) PR_FindFunctionSymbol(mXineramalib, "XineramaIsActive"); _XnrmQueryScreens_fn _XnrmQueryScreens = (_XnrmQueryScreens_fn) PR_FindFunctionSymbol(mXineramalib, "XineramaQueryScreens"); // get the number of screens via xinerama Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); if (_XnrmIsActive && _XnrmQueryScreens && _XnrmIsActive(display)) { screenInfo = _XnrmQueryScreens(display, &numScreens); } } // screenInfo == nullptr if either Xinerama couldn't be loaded or // isn't running on the current display if (!screenInfo || numScreens == 1) { numScreens = 1; #endif RefPtr<nsScreenGtk> screen; if (mCachedScreenArray.Count() > 0) { screen = static_cast<nsScreenGtk*>(mCachedScreenArray[0]); } else { screen = new nsScreenGtk(); if (!screen || !mCachedScreenArray.AppendObject(screen)) { return NS_ERROR_OUT_OF_MEMORY; } } screen->Init(mRootWindow); #ifdef MOZ_X11 } // If Xinerama is enabled and there's more than one screen, fill // in the info for all of the screens. If that's not the case // then nsScreenGTK() defaults to the screen width + height else { #ifdef DEBUG printf("Xinerama superpowers activated for %d screens!\n", numScreens); #endif for (int i = 0; i < numScreens; ++i) { RefPtr<nsScreenGtk> screen; if (mCachedScreenArray.Count() > i) { screen = static_cast<nsScreenGtk*>(mCachedScreenArray[i]); } else { screen = new nsScreenGtk(); if (!screen || !mCachedScreenArray.AppendObject(screen)) { return NS_ERROR_OUT_OF_MEMORY; } } // initialize this screen object screen->Init(&screenInfo[i]); } } // Remove any screens that are no longer present. while (mCachedScreenArray.Count() > numScreens) { mCachedScreenArray.RemoveObjectAt(mCachedScreenArray.Count() - 1); } if (screenInfo) { XFree(screenInfo); } #endif return NS_OK; }
int _wnck_error_trap_pop (void) { XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False); return gdk_error_trap_pop (); }
/* Code to find the active window in order to collect stats for social * application browsing. */ static void get_active_application_properties(HippoIdleMonitor *monitor, char **wm_class, char **title) { Display *xdisplay = GDK_DISPLAY_XDISPLAY(monitor->display); int n_screens = gdk_display_get_n_screens(monitor->display); Atom net_active_window_x = gdk_x11_get_xatom_by_name_for_display(monitor->display, "_NET_ACTIVE_WINDOW"); GdkAtom net_active_window_gdk = gdk_atom_intern("_NET_ACTIVE_WINDOW", FALSE); Window active_window = None; int i; Atom type; int format; unsigned long n_items; unsigned long bytes_after; guchar *data; if (wm_class) *wm_class = NULL; if (title) *title = NULL; /* Find the currently focused window by looking at the _NET_ACTIVE_WINDOW property * on all the screens of the display. */ for (i = 0; i < n_screens; i++) { GdkScreen *screen = gdk_display_get_screen(monitor->display, i); GdkWindow *root = gdk_screen_get_root_window(screen); if (!gdk_x11_screen_supports_net_wm_hint (screen, net_active_window_gdk)) continue; XGetWindowProperty (xdisplay, GDK_DRAWABLE_XID(root), net_active_window_x, 0, 1, False, XA_WINDOW, &type, &format, &n_items, &bytes_after, &data); if (type == XA_WINDOW) { active_window = *(Window *)data; XFree(data); break; } } /* Now that we have the active window, figure out the application name and WM class */ gdk_error_trap_push(); if (active_window && wm_class) { if (XGetWindowProperty (xdisplay, active_window, XA_WM_CLASS, 0, G_MAXLONG, False, XA_STRING, &type, &format, &n_items, &bytes_after, &data) == Success && type == XA_STRING) { if (format == 8) { char **list; int count; count = gdk_text_property_to_utf8_list_for_display(monitor->display, GDK_TARGET_STRING, 8, data, n_items, &list); if (count > 1) *wm_class = g_strdup(list[1]); if (list) g_strfreev(list); } XFree(data); } } if (active_window && title) { Atom utf8_string = gdk_x11_get_xatom_by_name_for_display(monitor->display, "UTF8_STRING"); if (XGetWindowProperty (xdisplay, active_window, gdk_x11_get_xatom_by_name_for_display(monitor->display, "_NET_WM_NAME"), 0, G_MAXLONG, False, utf8_string, &type, &format, &n_items, &bytes_after, &data) == Success && type == utf8_string) { if (format == 8 && g_utf8_validate((char *)data, -1, NULL)) { *title = g_strdup((char *)data); } XFree(data); } } if (active_window && title && *title == NULL) { if (XGetWindowProperty (xdisplay, active_window, XA_WM_NAME, 0, G_MAXLONG, False, AnyPropertyType, &type, &format, &n_items, &bytes_after, &data) == Success && type != None) { if (format == 8) { char **list; int count; count = gdk_text_property_to_utf8_list_for_display(monitor->display, gdk_x11_xatom_to_atom_for_display(monitor->display, type), 8, data, n_items, &list); if (count > 0) *title = g_strdup(list[0]); if (list) g_strfreev(list); } XFree(data); } } gdk_error_trap_pop(); }
static gboolean poll_for_idleness (void *data) { HippoIdleMonitor *monitor = data; int i; int n_screens; unsigned long idle_time; gboolean was_idle; idle_time = G_MAXINT; n_screens = gdk_display_get_n_screens(monitor->display); for (i = 0; i < n_screens; ++i) { int result; GdkScreen *screen; screen = gdk_display_get_screen(monitor->display, i); result = XScreenSaverQueryInfo(GDK_DISPLAY_XDISPLAY(monitor->display), GDK_SCREEN_XSCREEN(screen)->root, monitor->info); if (result == 0) { g_warning("Failed to get idle time from screensaver extension"); break; } /* monitor->info->idle is time in milliseconds since last user interaction event */ idle_time = MIN(monitor->info->idle, idle_time); } was_idle = monitor->currently_idle; /* If the idle time has gone down, there must have been activity since we last checked */ if (idle_time < monitor->last_idle) { monitor->activity_time = get_time(); monitor->currently_idle = FALSE; } else { /* If no activity, see how long ago it was and count ourselves idle * if it's been a short while. We keep this idle really short, since it * simply results in keeping bubbles up; we want to do this if people * just look away for a minute, really. It can be "more aggressive" * about idle detection than a screensaver would be. */ GTime now = get_time(); if (now < monitor->activity_time) { /* clock went backward... just "catch up" * then wait until the idle timeout expires again */ monitor->activity_time = now; } else if ((now - monitor->activity_time) > 120) { /* 120 = 2 minutes */ monitor->currently_idle = TRUE; } } monitor->last_idle = idle_time; if (was_idle != monitor->currently_idle) { (* monitor->func) (monitor->currently_idle, monitor->data); } if (hippo_data_cache_get_application_usage_enabled(monitor->cache) && !monitor->currently_idle) { update_application_info(monitor); } return TRUE; }
static gboolean gdk_check_xpending (GdkDisplay *display) { return XPending (GDK_DISPLAY_XDISPLAY (display)); }
bool wxTopLevelWindowGTK::ShowFullScreen(bool show, long) { if (show == m_fsIsShowing) return false; // return what? m_fsIsShowing = show; #ifdef GDK_WINDOWING_X11 Display* xdpy = GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(m_widget)); Window xroot = GDK_WINDOW_XID(gtk_widget_get_root_window(m_widget)); wxX11FullScreenMethod method = wxGetFullScreenMethodX11(xdpy, (WXWindow)xroot); // NB: gtk_window_fullscreen() uses freedesktop.org's WMspec extensions // to switch to fullscreen, which is not always available. We must // check if WM supports the spec and use legacy methods if it // doesn't. if ( method == wxX11_FS_WMSPEC ) #endif // GDK_WINDOWING_X11 { if (show) gtk_window_fullscreen( GTK_WINDOW( m_widget ) ); else gtk_window_unfullscreen( GTK_WINDOW( m_widget ) ); } #ifdef GDK_WINDOWING_X11 else { GdkWindow* window = gtk_widget_get_window(m_widget); Window xid = GDK_WINDOW_XID(window); if (show) { GetPosition( &m_fsSaveFrame.x, &m_fsSaveFrame.y ); GetSize( &m_fsSaveFrame.width, &m_fsSaveFrame.height ); GdkScreen* screen = gtk_widget_get_screen(m_widget); const int screen_width = gdk_screen_get_width(screen); const int screen_height = gdk_screen_get_height(screen); gint client_x, client_y, root_x, root_y; gint width, height; m_fsSaveGdkFunc = m_gdkFunc; m_fsSaveGdkDecor = m_gdkDecor; m_gdkFunc = m_gdkDecor = 0; gdk_window_set_decorations(window, (GdkWMDecoration)0); gdk_window_set_functions(window, (GdkWMFunction)0); gdk_window_get_origin(window, &root_x, &root_y); gdk_window_get_geometry(window, &client_x, &client_y, &width, &height); gdk_window_move_resize( window, -client_x, -client_y, screen_width + 1, screen_height + 1); wxSetFullScreenStateX11(xdpy, (WXWindow)xroot, (WXWindow)xid, show, &m_fsSaveFrame, method); } else // hide { m_gdkFunc = m_fsSaveGdkFunc; m_gdkDecor = m_fsSaveGdkDecor; gdk_window_set_decorations(window, (GdkWMDecoration)m_gdkDecor); gdk_window_set_functions(window, (GdkWMFunction)m_gdkFunc); wxSetFullScreenStateX11(xdpy, (WXWindow)xroot, (WXWindow)xid, show, &m_fsSaveFrame, method); SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y, m_fsSaveFrame.width, m_fsSaveFrame.height); } } #endif // GDK_WINDOWING_X11 // documented behaviour is to show the window if it's still hidden when // showing it full screen if (show) Show(); return true; }
bool WebEmberX11::onX11Event(FB::X11Event *evt, FB::PluginWindow * pwin) { //Do not handle event if: //-It's not the active firebreath window. //-When the event is sent by XSendEvent. It could be our injected event and it could loop forever. if (pwin != (FB::PluginWindow*)mPluginWindow || evt->m_event->any.send_event == true){ return true; } switch (evt->m_event->type) { case GDK_MOTION_NOTIFY: { injectMotionToSDL((GdkEventMotion*)evt->m_event); } break; case GDK_BUTTON_PRESS: { GdkEventButton* buttonevent = (GdkEventButton*)evt->m_event; injectButtonToSDL(buttonevent); if (!mFocus) { Display* display = GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(mPluginWindow->getWidget())); XSetInputFocus(display, mWindow, RevertToParent, buttonevent->time); gtk_widget_grab_focus(mPluginWindow->getWidget()); } } break; case GDK_BUTTON_RELEASE: { injectButtonToSDL((GdkEventButton*)evt->m_event); } break; case GDK_KEY_RELEASE: case GDK_KEY_PRESS: { injectKeyToSDL((GdkEventKey*)evt->m_event); } break; case GDK_FOCUS_CHANGE: { GdkEventFocus* focus = (GdkEventFocus*)evt->m_event; if (focus->in) { mFocus = true; } else { mFocus = false; } } break; case GDK_VISIBILITY_NOTIFY: { GdkEventVisibility* visibility = (GdkEventVisibility*)evt->m_event; if (visibility->state != GDK_VISIBILITY_FULLY_OBSCURED) { if (!mVisible) { mVisible = true; injectVisibilityToSDL(mVisible); //XFlush(mDisplaySDL); } } else { if (mVisible) { mVisible = false; injectVisibilityToSDL(mVisible); //XFlush(mDisplaySDL); } } } break; } //Returns true to never use the firebreath's default event handling. return true; }
bool wxTopLevelWindowGTK::Show( bool show ) { wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); #ifdef GDK_WINDOWING_X11 bool deferShow = show && !m_isShown && m_deferShow; if (deferShow) { deferShow = m_deferShowAllowed && gs_requestFrameExtentsStatus != 2 && !gtk_widget_get_realized(m_widget) && g_signal_handler_find(m_widget, GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA), g_signal_lookup("property_notify_event", GTK_TYPE_WIDGET), 0, NULL, NULL, this); if (deferShow) { GdkScreen* screen = gtk_widget_get_screen(m_widget); GdkAtom atom = gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false); deferShow = gdk_x11_screen_supports_net_wm_hint(screen, atom) != 0; // If _NET_REQUEST_FRAME_EXTENTS not supported, don't allow changes // to m_decorSize, it breaks saving/restoring window size with // GetSize()/SetSize() because it makes window bigger between each // restore and save. m_updateDecorSize = deferShow; } m_deferShow = deferShow; } if (deferShow) { // Initial show. If WM supports _NET_REQUEST_FRAME_EXTENTS, defer // calling gtk_widget_show() until _NET_FRAME_EXTENTS property // notification is received, so correct frame extents are known. // This allows resizing m_widget to keep the overall size in sync with // what wxWidgets expects it to be without an obvious change in the // window size immediately after it becomes visible. // Realize m_widget, so m_widget->window can be used. Realizing normally // causes the widget tree to be size_allocated, which generates size // events in the wrong order. However, the size_allocates will not be // done if the allocation is not the default (1,1). GtkAllocation alloc; gtk_widget_get_allocation(m_widget, &alloc); const int alloc_width = alloc.width; if (alloc_width == 1) { alloc.width = 2; gtk_widget_set_allocation(m_widget, &alloc); } gtk_widget_realize(m_widget); if (alloc_width == 1) { alloc.width = 1; gtk_widget_set_allocation(m_widget, &alloc); } // send _NET_REQUEST_FRAME_EXTENTS XClientMessageEvent xevent; memset(&xevent, 0, sizeof(xevent)); xevent.type = ClientMessage; GdkWindow* window = gtk_widget_get_window(m_widget); xevent.window = GDK_WINDOW_XID(window); xevent.message_type = gdk_x11_atom_to_xatom_for_display( gdk_window_get_display(window), gdk_atom_intern("_NET_REQUEST_FRAME_EXTENTS", false)); xevent.format = 32; Display* display = GDK_DISPLAY_XDISPLAY(gdk_window_get_display(window)); XSendEvent(display, DefaultRootWindow(display), false, SubstructureNotifyMask | SubstructureRedirectMask, (XEvent*)&xevent); if (gs_requestFrameExtentsStatus == 0) { // if WM does not respond to request within 1 second, // we assume support for _NET_REQUEST_FRAME_EXTENTS is not working m_netFrameExtentsTimerId = g_timeout_add(1000, request_frame_extents_timeout, this); } // defer calling gtk_widget_show() m_isShown = true; return true; } #endif // GDK_WINDOWING_X11 if (show && !gtk_widget_get_realized(m_widget)) { // size_allocate signals occur in reverse order (bottom to top). // Things work better if the initial wxSizeEvents are sent (from the // top down), before the initial size_allocate signals occur. wxSizeEvent event(GetSize(), GetId()); event.SetEventObject(this); HandleWindowEvent(event); } bool change = base_type::Show(show); if (change && !show) { // make sure window has a non-default position, so when it is shown // again, it won't be repositioned by WM as if it were a new window // Note that this must be done _after_ the window is hidden. gtk_window_move((GtkWindow*)m_widget, m_x, m_y); } return change; }
int main(int argc, char **argv) { GOptionContext *context; GError *error = NULL; ShellGlobal *global; GjsContext *js_context; char *script; const char *filename; char *title; gsize len; int code; gtk_init (&argc, &argv); clutter_x11_set_display (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ())); clutter_x11_disable_event_retrieval (); if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; gdk_window_add_filter (NULL, event_filter, NULL); context = g_option_context_new (NULL); /* pass unknown through to the JS script */ g_option_context_set_ignore_unknown_options (context, TRUE); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) g_error ("option parsing failed: %s", error->message); setlocale (LC_ALL, ""); g_type_init (); _shell_global_init (NULL); global = shell_global_get (); js_context = _shell_global_get_gjs_context (global); /* prepare command line arguments */ if (!gjs_context_define_string_array (js_context, "ARGV", argc - 2, (const char**)argv + 2, &error)) { g_printerr ("Failed to defined ARGV: %s", error->message); exit (1); } if (command != NULL) { script = command; len = strlen (script); filename = "<command line>"; } else if (argc <= 1) { script = g_strdup ("const Console = imports.console; Console.interact();"); len = strlen (script); filename = "<stdin>"; } else /*if (argc >= 2)*/ { error = NULL; if (!g_file_get_contents (argv[1], &script, &len, &error)) { g_printerr ("%s\n", error->message); exit (1); } filename = argv[1]; } title = g_filename_display_basename (filename); g_set_prgname (title); g_free (title); #if HAVE_BLUETOOTH /* The module imports are all so intertwined that if the test * imports anything in js/ui, it will probably eventually end up * pulling in ui/status/bluetooth.js. So we need this. */ g_irepository_prepend_search_path (BLUETOOTH_DIR); #endif /* evaluate the script */ error = NULL; if (!gjs_context_eval (js_context, script, len, filename, &code, &error)) { g_free (script); g_printerr ("%s\n", error->message); exit (1); } g_free (script); exit (code); }
void gdk_property_change (GdkWindow *window, GdkAtom property, GdkAtom type, gint format, GdkPropMode mode, const guchar *data, gint nelements) { GdkDisplay *display; Window xwindow; Atom xproperty; Atom xtype; g_return_if_fail (!window || GDK_WINDOW_IS_X11 (window)); if (!window) { GdkScreen *screen; screen = gdk_screen_get_default (); window = gdk_screen_get_root_window (screen); GDK_NOTE (MULTIHEAD, g_message ("gdk_property_change(): window is NULL\n")); } else if (!GDK_WINDOW_IS_X11 (window)) return; if (GDK_WINDOW_DESTROYED (window)) return; gdk_window_ensure_native (window); display = gdk_drawable_get_display (window); xproperty = gdk_x11_atom_to_xatom_for_display (display, property); xtype = gdk_x11_atom_to_xatom_for_display (display, type); xwindow = GDK_WINDOW_XID (window); if (xtype == XA_ATOM || xtype == gdk_x11_get_xatom_by_name_for_display (display, "ATOM_PAIR")) { /* * data is an array of GdkAtom, we need to convert it * to an array of X Atoms */ gint i; GdkAtom *atoms = (GdkAtom*) data; Atom *xatoms; xatoms = g_new (Atom, nelements); for (i = 0; i < nelements; i++) xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, atoms[i]); XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow, xproperty, xtype, format, mode, (guchar *)xatoms, nelements); g_free (xatoms); } else XChangeProperty (GDK_DISPLAY_XDISPLAY (display), xwindow, xproperty, xtype, format, mode, (guchar *)data, nelements); }
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); }
static void _xim_preedit_callback_draw (XIMS xims, X11IC *x11ic, const gchar *preedit_string, IBusAttrList *attr_list) { IMPreeditCBStruct pcb; XIMText text; XTextProperty tp; static XIMFeedback *feedback; static gint feedback_len = 0; guint j, i, len; if (preedit_string == NULL) return; len = g_utf8_strlen (preedit_string, -1); if (len + 1 > feedback_len) { feedback_len = (len + 1 + 63) & ~63; if (feedback) { feedback = g_renew (XIMFeedback, feedback, feedback_len); } else { feedback = g_new (XIMFeedback, feedback_len); } } for (i = 0; i < len; i++) { feedback[i] = 0; } if (attr_list != NULL) { for (i = 0;; i++) { XIMFeedback attr = 0; IBusAttribute *ibus_attr = ibus_attr_list_get (attr_list, i); if (ibus_attr == NULL) { break; } switch (ibus_attr->type) { case IBUS_ATTR_TYPE_UNDERLINE: if (ibus_attr->value == IBUS_ATTR_UNDERLINE_SINGLE) { attr = XIMUnderline; } break; case IBUS_ATTR_TYPE_BACKGROUND: { if (ibus_attr->value != 0xffffff) { attr = XIMReverse; } break; } default: continue; } for (j = ibus_attr->start_index; j < ibus_attr->end_index; j++) { feedback[j] |= attr; } } } for (i = 0; i < len; i++) { if (feedback[i] == 0) { feedback[i] = XIMUnderline; } } feedback[len] = 0; pcb.major_code = XIM_PREEDIT_DRAW; pcb.connect_id = x11ic->connect_id; pcb.icid = x11ic->icid; pcb.todo.draw.caret = len; pcb.todo.draw.chg_first = 0; pcb.todo.draw.chg_length = x11ic->onspot_preedit_length; pcb.todo.draw.text = &text; text.feedback = feedback; if (len > 0) { Xutf8TextListToTextProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), (char **)&preedit_string, 1, XCompoundTextStyle, &tp); text.encoding_is_wchar = 0; text.length = strlen ((char*)tp.value); text.string.multi_byte = (char*)tp.value; IMCallCallback (xims, (XPointer) & pcb); XFree (tp.value); } else { text.encoding_is_wchar = 0; text.length = 0; text.string.multi_byte = ""; IMCallCallback (xims, (XPointer) & pcb); len = 0; } x11ic->onspot_preedit_length = len; }
static void test_error_trapping (GdkDisplay *gdk_display) { Display *d; int dummy; int error; d = GDK_DISPLAY_XDISPLAY (gdk_display); /* verify that we can catch errors */ gdk_error_trap_push (); XListProperties (d, 0, &dummy); /* round trip */ error = gdk_error_trap_pop (); g_assert (error == BadWindow); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); /* not a round trip */ XSetCloseDownMode (d, DestroyAll); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* try the same without sync */ gdk_error_trap_push (); XListProperties (d, 0, &dummy); gdk_error_trap_pop_ignored (); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); XSetCloseDownMode (d, DestroyAll); gdk_error_trap_pop_ignored (); XSync (d, TRUE); /* verify that we can catch with nested traps; inner-most * active trap gets the error */ gdk_error_trap_push (); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); error = gdk_error_trap_pop (); g_assert (error == BadValue); error = gdk_error_trap_pop (); g_assert (error == Success); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_push (); error = gdk_error_trap_pop (); g_assert (error == Success); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* try nested, without sync */ gdk_error_trap_push (); gdk_error_trap_push (); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_pop_ignored (); gdk_error_trap_pop_ignored (); gdk_error_trap_pop_ignored (); XSync (d, TRUE); /* try nested, without sync, with interleaved calls */ gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_pop_ignored (); XSetCloseDownMode (d, 12345); gdk_error_trap_pop_ignored (); XSetCloseDownMode (d, 12345); gdk_error_trap_pop_ignored (); XSync (d, TRUE); /* don't want to get errors that weren't in our push range */ gdk_error_trap_push (); XSetCloseDownMode (d, 12345); gdk_error_trap_push (); XSync (d, TRUE); /* not an error */ error = gdk_error_trap_pop (); g_assert (error == Success); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* non-roundtrip non-error request after error request, inside trap */ gdk_error_trap_push (); XSetCloseDownMode (d, 12345); XMapWindow (d, DefaultRootWindow (d)); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* a non-roundtrip non-error request before error request, inside trap */ gdk_error_trap_push (); XMapWindow (d, DefaultRootWindow (d)); XSetCloseDownMode (d, 12345); error = gdk_error_trap_pop (); g_assert (error == BadValue); /* Not part of any test, just a double-check * that all errors have arrived */ XSync (d, TRUE); }
static PyObject * osk_struts_set (PyObject *self, PyObject *args) { Display *dpy; unsigned long xid; unsigned long struts[12] = { 0, }; PyObject *obj, *seq, **items; int i; if (!PyArg_ParseTuple (args, "kO", &xid, &obj)) return NULL; seq = PySequence_Fast (obj, "expected sequence type"); if (!seq) return NULL; if (PySequence_Fast_GET_SIZE (seq) != 12) { PyErr_SetString (PyExc_ValueError, "expected 12 values"); return NULL; } items = PySequence_Fast_ITEMS (seq); for (i = 0; i < 12; i++, items++) { struts[i] = PyLong_AsUnsignedLongMask (*items); if (PyErr_Occurred ()) { Py_DECREF (seq); return NULL; } if (struts[i] < 0) { PyErr_SetString (PyExc_ValueError, "expected value >= 0"); Py_DECREF (seq); return NULL; } } Py_DECREF (seq); dpy = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); gdk_error_trap_push (); XChangeProperty (dpy, xid, XInternAtom (dpy, "_NET_WM_STRUT", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 4); XChangeProperty (dpy, xid, XInternAtom (dpy, "_NET_WM_STRUT_PARTIAL", False), XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &struts, 12); gdk_error_trap_pop_ignored (); Py_RETURN_NONE; }
int main(int argc, char *argv[], char *env[]) { int i; const char* desktop_name; char *file; setlocale(LC_CTYPE, ""); #if !GLIB_CHECK_VERSION(2, 32, 0) g_thread_init(NULL); #endif /* gdk_threads_init(); gdk_threads_enter(); */ gtk_init(&argc, &argv); #ifdef ENABLE_NLS bindtextdomain ( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR ); bind_textdomain_codeset ( GETTEXT_PACKAGE, "UTF-8" ); textdomain ( GETTEXT_PACKAGE ); #endif XSetLocaleModifiers(""); XSetErrorHandler((XErrorHandler) panel_handle_x_error); resolve_atoms(); desktop_name = g_getenv("XDG_CURRENT_DESKTOP"); is_in_lxde = desktop_name && (0 == strcmp(desktop_name, "LXDE")); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { usage(); exit(0); } else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { printf("lxpanel %s\n", version); exit(0); } else if (!strcmp(argv[i], "--log")) { i++; if (i == argc) { g_critical( "lxpanel: missing log level"); usage(); exit(1); } else { /* deprecated */ } } else if (!strcmp(argv[i], "--configure") || !strcmp(argv[i], "-C")) { config = 1; } else if (!strcmp(argv[i], "--profile") || !strcmp(argv[i], "-p")) { i++; if (i == argc) { g_critical( "lxpanel: missing profile name"); usage(); exit(1); } else { cprofile = g_strdup(argv[i]); } } else { printf("lxpanel: unknown option - %s\n", argv[i]); usage(); exit(1); } } /* Add a gtkrc file to be parsed too. */ file = _user_config_file_name("gtkrc", NULL); gtk_rc_parse(file); g_free(file); /* Check for duplicated lxpanel instances */ if (!check_main_lock() && !config) { printf("There is already an instance of LXPanel. Now to exit\n"); exit(1); } _ensure_user_config_dirs(); /* Add our own icons to the search path of icon theme */ gtk_icon_theme_append_search_path( gtk_icon_theme_get_default(), PACKAGE_DATA_DIR "/images" ); fbev = fb_ev_new(); is_restarting = FALSE; /* init LibFM */ fm_gtk_init(NULL); /* prepare modules data */ lxpanel_prepare_modules(); init_static_plugins(); load_global_config(); /* NOTE: StructureNotifyMask is required by XRandR * See init_randr_support() in gdkscreen-x11.c of gtk+ for detail. */ gdk_window_set_events(gdk_get_default_root_window(), GDK_STRUCTURE_MASK | GDK_SUBSTRUCTURE_MASK | GDK_PROPERTY_CHANGE_MASK); gdk_window_add_filter(gdk_get_default_root_window (), (GdkFilterFunc)panel_event_filter, NULL); if( G_UNLIKELY( ! start_all_panels() ) ) g_warning( "Config files are not found.\n" ); /* * FIXME: configure?? if (config) configure(); */ gtk_main(); XSelectInput (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), GDK_ROOT_WINDOW(), NoEventMask); gdk_window_remove_filter(gdk_get_default_root_window (), (GdkFilterFunc)panel_event_filter, NULL); /* destroy all panels */ g_slist_foreach( all_panels, (GFunc) gtk_widget_destroy, NULL ); g_slist_free( all_panels ); all_panels = NULL; g_free( cfgfile ); free_global_config(); lxpanel_unload_modules(); fm_gtk_finalize(); /* gdk_threads_leave(); */ g_object_unref(fbev); if (!is_restarting) return 0; if (strchr(argv[0], G_DIR_SEPARATOR)) execve(argv[0], argv, env); else execve(g_find_program_in_path(argv[0]), argv, env); return 1; }
/* * update_event_windows * * Returns: void * Description: creates small "event windows" for the buttons specified to be * on the titlebar by wnck. Note here that for the pixmap mode we create actual * X windows but in the reparenting mode this is not possible so we create event * capture boxes on the window instead. The geometry of the decoration is retrieved * with window_get_client_window_geometry and adjusted for shade. Also we * need to query the theme for what window positions are appropriate here. * * This function works on the buttons and also the small event regions that we need * in order to toggle certain actions on the window decoration (eg resize, move) * * So your window decoration might look something like this (not to scale): * * ----------------------------------------------------------- * | rtl | rt | rtr | * | --- |---------------------------------------------| --- | * | | [i][s][m] mv [_][M][X] | | * | |---------------------------------------------| | * | | | | * | rl | window contents | rr | * | | | | * | | | | * | --- |---------------------------------------------| --- | * | rbl | rb | rbr | * ----------------------------------------------------------- * * Where: * - rtl = resize top left * - rtr = resize top right * - rbl = resize bottom left * - rbr = resize bottom right * - rt = resize top * - rb = resize bottom * - rl = resize left * - rr = resize right * - mv = "grab move" area (eg titlebar) * - i = icon * - s = shade * - m = menu * - _ = minimize * - M = maximize * - X = close * * For the reparenting mode we use button_windows[i].pos and for the pixmap mode * we use buttons_windows[i].window * */ void update_event_windows (WnckWindow *win) { Display *xdisplay; decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); gint x0, y0, width, height, x, y, w, h; gint i, j, k, l; gint actions = d->actions; xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); /* Get the geometry of the client */ wnck_window_get_client_window_geometry (win, &x0, &y0, &width, &height); /* Shaded windows have no height - also skip some event windows */ if (d->state & WNCK_WINDOW_STATE_SHADED) { height = 0; k = l = 1; } else { k = 0; l = 2; } gdk_error_trap_push (); /* [rtl, ru, rtr], [rl, mv, rr], [rbl, rb, rbr] */ for (i = 0; i < 3; ++i) { static guint event_window_actions[3][3] = { { WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_RESIZE }, { WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_MOVE, WNCK_WINDOW_ACTION_RESIZE }, { WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_RESIZE, WNCK_WINDOW_ACTION_RESIZE } }; for (j = 0; j < 3; ++j) { w = 0; h = 0; if (actions & event_window_actions[i][j] && i >= k && i <= l) (*theme_get_event_window_position) (d, i, j, width, height, &x, &y, &w, &h); /* Reparenting mode - create boxes which we monitor motionnotify on */ if (d->frame_window) { BoxPtr box = &d->event_windows[i][j].pos; box->x1 = x; box->x2 = x + w; box->y1 = y; box->y2 = y + h; } /* Pixmap mode with window geometry - create small event windows */ else if (!d->frame_window && w != 0 && h != 0) { XMapWindow (xdisplay, d->event_windows[i][j].window); XMoveResizeWindow (xdisplay, d->event_windows[i][j].window, x, y, w, h); } /* No parent and no geometry - unmap all event windows */ else if (!d->frame_window) { XUnmapWindow (xdisplay, d->event_windows[i][j].window); } } } /* no button event windows if width is less than minimum width */ if (width < ICON_SPACE + d->button_width) actions = 0; /* Above, stick, unshade and unstick are only available in wnck => 2.18.1 */ for (i = 0; i < BUTTON_NUM; ++i) { static guint button_actions[BUTTON_NUM] = { WNCK_WINDOW_ACTION_CLOSE, WNCK_WINDOW_ACTION_MAXIMIZE, WNCK_WINDOW_ACTION_MINIMIZE, 0, WNCK_WINDOW_ACTION_SHADE, WNCK_WINDOW_ACTION_ABOVE, WNCK_WINDOW_ACTION_STICK, WNCK_WINDOW_ACTION_UNSHADE, WNCK_WINDOW_ACTION_ABOVE, WNCK_WINDOW_ACTION_UNSTICK }; /* Reparenting mode - if a box was set and we no longer need it reset its geometry */ if (d->frame_window && button_actions[i] && !(actions & button_actions[i])) { memset (&d->button_windows[i].pos, 0, sizeof (Box)); } /* Pixmap mode - if a box was set and we no longer need it unmap its window */ else if (!d->frame_window && button_actions[i] && !(actions & button_actions[i])) { XUnmapWindow (xdisplay, d->button_windows[i].window); continue; } /* Reparenting mode - if there is a button position for this * button then set the geometry */ if (d->frame_window && (*theme_get_button_position) (d, i, width, height, &x, &y, &w, &h)) { BoxPtr box = &d->button_windows[i].pos; box->x1 = x; box->y1 = y; box->x2 = x + w; box->y2 = y + h; } /* Pixmap mode - if there is a button position for this button then map the window * and resize it to this position */ else if (!d->frame_window && (*theme_get_button_position) (d, i, width, height, &x, &y, &w, &h)) { Window x11_win = d->button_windows[i].window; XMapWindow (xdisplay, x11_win); XMoveResizeWindow (xdisplay, x11_win, x, y, w, h); } else if (!d->frame_window) { XUnmapWindow (xdisplay, d->button_windows[i].window); } } gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop_ignored (); }
/* * Keep code in panel-applet-bindings.c in sync! */ guint panel_get_real_modifier_mask (guint mask) { guint real_mask; Display *display; int i, min_keycode, max_keycode, keysyms_per_keycode; int max_keycodes_per_modifier; KeySym *keysyms_for_keycodes; XModifierKeymap *modifier_keymap; real_mask = mask & ((Mod5Mask << 1) - 1); /* Already real */ if (mask == real_mask) { return mask; } display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); XDisplayKeycodes (display, &min_keycode, &max_keycode); keysyms_for_keycodes = XGetKeyboardMapping (display, min_keycode, max_keycode - min_keycode + 1, &keysyms_per_keycode); modifier_keymap = XGetModifierMapping (display); max_keycodes_per_modifier = modifier_keymap->max_keypermod; /* Loop through all the modifiers and find out which "real" * (Mod2..Mod5) modifiers Super, Hyper, and Meta are mapped to. * Note, Mod1 is used by the Alt modifier */ for (i = Mod2MapIndex * max_keycodes_per_modifier; i < (Mod5MapIndex + 1) * max_keycodes_per_modifier; i++) { int keycode; int j; KeySym *keysyms_for_keycode; int map_index; int map_mask; keycode = modifier_keymap->modifiermap[i]; /* The array is sparse, there may be some * empty entries. Filter those out * (along with any invalid entries) */ if (keycode < min_keycode || keycode > max_keycode) continue; keysyms_for_keycode = keysyms_for_keycodes + (keycode - min_keycode) * keysyms_per_keycode; map_index = i / max_keycodes_per_modifier; g_assert (map_index <= Mod5MapIndex); map_mask = 1 << map_index; for (j = 0; j < keysyms_per_keycode; j++) { switch (keysyms_for_keycode[j]) { case XK_Super_L: case XK_Super_R: if (mask & GDK_SUPER_MASK) real_mask |= map_mask; break; case XK_Hyper_L: case XK_Hyper_R: if (mask & GDK_HYPER_MASK) real_mask |= map_mask; break; case XK_Meta_L: case XK_Meta_R: if (mask & GDK_META_MASK) real_mask |= map_mask; break; default: break; } } } XFreeModifiermap (modifier_keymap); XFree (keysyms_for_keycodes); return real_mask; }
int main(int argc, char** argv) { gdk_init(&argc, &argv); #if defined(HAVE_LIBXSS) && defined(MOZ_WIDGET_GTK) int event_base, error_base; Bool have_xscreensaver = XScreenSaverQueryExtension(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &event_base, &error_base); if (!have_xscreensaver) { fprintf(stderr, "No XScreenSaver extension on display\n"); } else { XScreenSaverInfo* info = XScreenSaverAllocInfo(); if (!info) { fprintf(stderr, "%s: Out of memory\n", argv[0]); return 1; } XScreenSaverQueryInfo(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), GDK_ROOT_WINDOW(), info); const char* state; const char* til_or_since = nullptr; switch (info->state) { case ScreenSaverOff: state = "Off"; til_or_since = "XScreenSaver will activate after another %lu seconds idle time\n"; break; case ScreenSaverOn: state = "On"; if (info->til_or_since) { til_or_since = "XScreenSaver idle timer activated %lu seconds ago\n"; } else { til_or_since = "XScreenSaver idle activation is disabled\n"; } break; case ScreenSaverDisabled: state = "Disabled"; break; default: state = "unknown"; } const char* kind; switch (info->kind) { case ScreenSaverBlanked: kind = "Blanked"; break; case ScreenSaverInternal: state = "Internal"; break; case ScreenSaverExternal: state = "External"; break; default: state = "unknown"; } fprintf(stderr, "XScreenSaver state: %s\n", state); if (til_or_since) { fprintf(stderr, "XScreenSaver kind: %s\n", kind); fprintf(stderr, til_or_since, info->til_or_since / 1000); } fprintf(stderr, "User input has been idle for %lu seconds\n", info->idle / 1000); XFree(info); } #endif GdkPixbuf* screenshot = nullptr; GdkWindow* window = gdk_get_default_root_window(); #if (MOZ_WIDGET_GTK == 2) screenshot = gdk_pixbuf_get_from_drawable(nullptr, window, nullptr, 0, 0, 0, 0, gdk_screen_width(), gdk_screen_height()); #else screenshot = gdk_pixbuf_get_from_window(window, 0, 0, gdk_window_get_width(window), gdk_window_get_height(window)); #endif if (!screenshot) { fprintf(stderr, "%s: failed to create screenshot GdkPixbuf\n", argv[0]); return 1; } GError* error = nullptr; if (argc > 1) { gdk_pixbuf_save(screenshot, argv[1], "png", &error, nullptr); } else { gdk_pixbuf_save_to_callback(screenshot, save_to_stdout, nullptr, "png", &error, nullptr); } if (error) { fprintf(stderr, "%s: failed to write screenshot as png: %s\n", argv[0], error->message); return error->code; } return 0; }
static gboolean na_tray_manager_manage_screen_x11 (NaTrayManager *manager, GdkScreen *screen) { GdkDisplay *display; Screen *xscreen; GtkWidget *invisible; GdkWindow *window; char *selection_atom_name; guint32 timestamp; g_return_val_if_fail (NA_IS_TRAY_MANAGER (manager), FALSE); g_return_val_if_fail (manager->screen == NULL, FALSE); /* If there's already a manager running on the screen * we can't create another one. */ #if 0 if (na_tray_manager_check_running_screen_x11 (screen)) return FALSE; #endif manager->screen = screen; display = gdk_screen_get_display (screen); xscreen = GDK_SCREEN_XSCREEN (screen); invisible = gtk_invisible_new_for_screen (screen); gtk_widget_realize (invisible); gtk_widget_add_events (invisible, GDK_PROPERTY_CHANGE_MASK | GDK_STRUCTURE_MASK); selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d", gdk_screen_get_number (screen)); manager->selection_atom = gdk_atom_intern (selection_atom_name, FALSE); g_free (selection_atom_name); manager->invisible = invisible; g_object_ref (G_OBJECT (manager->invisible)); na_tray_manager_set_orientation_property (manager); na_tray_manager_set_visual_property (manager); na_tray_manager_set_padding_property (manager); na_tray_manager_set_icon_size_property (manager); na_tray_manager_set_colors_property (manager); window = gtk_widget_get_window (invisible); timestamp = gdk_x11_get_server_time (window); /* Check if we could set the selection owner successfully */ if (gdk_selection_owner_set_for_display (display, window, manager->selection_atom, timestamp, TRUE)) { XClientMessageEvent xev; GdkAtom opcode_atom; GdkAtom message_data_atom; xev.type = ClientMessage; xev.window = RootWindowOfScreen (xscreen); xev.message_type = gdk_x11_get_xatom_by_name_for_display (display, "MANAGER"); xev.format = 32; xev.data.l[0] = timestamp; xev.data.l[1] = gdk_x11_atom_to_xatom_for_display (display, manager->selection_atom); xev.data.l[2] = GDK_WINDOW_XID (window); xev.data.l[3] = 0; /* manager specific data */ xev.data.l[4] = 0; /* manager specific data */ XSendEvent (GDK_DISPLAY_XDISPLAY (display), RootWindowOfScreen (xscreen), False, StructureNotifyMask, (XEvent *)&xev); opcode_atom = gdk_atom_intern ("_NET_SYSTEM_TRAY_OPCODE", FALSE); manager->opcode_atom = gdk_x11_atom_to_xatom_for_display (display, opcode_atom); message_data_atom = gdk_atom_intern ("_NET_SYSTEM_TRAY_MESSAGE_DATA", FALSE); manager->message_data_atom = gdk_x11_atom_to_xatom_for_display (display, message_data_atom); /* Add a window filter */ #if 0 /* This is for when we lose the selection of _NET_SYSTEM_TRAY_Sx */ g_signal_connect (invisible, "selection-clear-event", G_CALLBACK (na_tray_manager_selection_clear_event), manager); #endif gdk_window_add_filter (window, na_tray_manager_window_filter, manager); return TRUE; } else { gtk_widget_destroy (invisible); g_object_unref (invisible); manager->invisible = NULL; manager->screen = NULL; return FALSE; } }
JNIEXPORT jobjectArray JNICALL Java_gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice_nativeGetDisplayModes (JNIEnv *env, jobject obj __attribute__((unused)), jobject gdkGraphicsEnv __attribute__((unused))) { #ifdef HAVE_XRANDR GdkDisplay *display; XRRScreenConfiguration *config; XRRScreenSize *screenSizes; int nsizes = 0, nrates = 0, i = 0; jclass x11DisplayMode_class; jmethodID x11DisplayMode_ctor; jobjectArray array; jobject instance; short *rates; jshortArray shortArray; display = (GdkDisplay *) NSA_GET_DISPLAY_PTR(env, gdkGraphicsEnv); gdk_threads_enter(); config = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY(display), GDK_ROOT_WINDOW()); screenSizes = XRRConfigSizes(config, &nsizes); x11DisplayMode_class = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice$X11DisplayMode"); x11DisplayMode_ctor = (*env)->GetMethodID(env, x11DisplayMode_class, "<init>", "(II[S)V"); array = (*env)->NewObjectArray(env, nsizes, x11DisplayMode_class, NULL); for (; i < nsizes ; i++) { /* Retrieves refresh rate information. */ rates = XRRConfigRates(config, i, &nrates); /* Create a Java short array and put them in. */ shortArray = (*env)->NewShortArray(env, nrates); (*env)->SetShortArrayRegion(env, shortArray, 0, nrates, (jshort *) rates); /* Create a GdkScreenGraphicsDevice.X11DisplayMode instance. */ instance = (*env)->NewObject(env, x11DisplayMode_class, x11DisplayMode_ctor, screenSizes[i].width, screenSizes[i].height, shortArray); /* Put it into the result array. */ (*env)->SetObjectArrayElement(env, array, i, instance); } /* Free everything acquired by xlib. */ XRRFreeScreenConfigInfo (config); gdk_threads_leave(); return array; #else JCL_ThrowException(env, "java/lang/InternalError", "Method should not have been invoked."); return NULL; #endif }
//______________________________________________ void ShadowHelper::installX11Shadows( GtkWidget* widget ) { #ifdef GDK_WINDOWING_X11 #if OXYGEN_DEBUG std::cerr << "Oxygen::ShadowHelper::installX11Shadows - " << " widget: " << widget << " wid: " << GDK_WINDOW_XID( gtk_widget_get_window( widget ) ) << std::endl; #endif // check widget if( !GTK_IS_WIDGET( widget ) ) return; // make sure handles and atom are defined createPixmapHandles(); GdkWindow *window = gtk_widget_get_window( widget ); GdkDisplay *display = gtk_widget_get_display( widget ); std::vector<unsigned long> data; const bool isMenu( this->isMenu( widget ) ); const bool isToolTip( this->isToolTip( widget ) ); if( _applicationName.isOpenOffice() || ( (isMenu||isToolTip) && _applicationName.isXul( widget ) ) ) { data = _squarePixmaps; data.push_back( _size ); data.push_back( _size ); data.push_back( _size ); data.push_back( _size ); } else { data = _roundPixmaps; if( isMenu ) { /* for menus, need to shrink top and bottom shadow size, since body is done likely with respect to real size in painting method (Oxygen::Style::renderMenuBackground) */ data.push_back( _size - Menu_VerticalOffset ); data.push_back( _size ); data.push_back( _size - Menu_VerticalOffset ); data.push_back( _size ); } else { // all sides have same sizz data.push_back( _size ); data.push_back( _size ); data.push_back( _size ); data.push_back( _size ); } } // change property XChangeProperty( GDK_DISPLAY_XDISPLAY( display ), GDK_WINDOW_XID(window), _atom, XA_CARDINAL, 32, PropModeReplace, reinterpret_cast<const unsigned char *>(&data[0]), data.size() ); #endif }