/** * ev_application_open_window: * @application: The instance of the application. * @timestamp: Current time value. * * Creates a new window */ void ev_application_open_window (EvApplication *application, GdkScreen *screen, guint32 timestamp) { GtkWidget *new_window = ev_window_new (); #ifdef GDK_WINDOWING_X11 GdkWindow *gdk_window; #endif if (screen) { ev_stock_icons_set_screen (screen); gtk_window_set_screen (GTK_WINDOW (new_window), screen); } if (!gtk_widget_get_realized (new_window)) gtk_widget_realize (new_window); #ifdef GDK_WINDOWING_X11 gdk_window = gtk_widget_get_window (GTK_WIDGET (new_window)); if (timestamp <= 0) timestamp = gdk_x11_get_server_time (gdk_window); gdk_x11_window_set_user_time (gdk_window, timestamp); gtk_window_present (GTK_WINDOW (new_window)); #else gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp); #endif /* GDK_WINDOWING_X11 */ }
static void tomboy_window_override_user_time (GtkWindow *window) { #ifdef GDK_WINDOWING_X11 guint32 ev_time = gtk_get_current_event_time(); if (ev_time == 0) { /* * FIXME: Global keypresses use an event filter on the root * window, which processes events before GDK sees them. */ ev_time = tomboy_keybinder_get_current_event_time (); } if (ev_time == 0) { gint ev_mask = gtk_widget_get_events (GTK_WIDGET(window)); if (!(ev_mask & GDK_PROPERTY_CHANGE_MASK)) { gtk_widget_add_events (GTK_WIDGET (window), GDK_PROPERTY_CHANGE_MASK); } /* * NOTE: Last resort for D-BUS or other non-interactive * openings. Causes roundtrip to server. Lame. */ ev_time = gdk_x11_get_server_time (gtk_widget_get_window(GTK_WIDGET(window))); } TRACE (g_print("Setting _NET_WM_USER_TIME to: %d\n", ev_time)); gdk_x11_window_set_user_time (gtk_widget_get_window(GTK_WIDGET(window)), ev_time); #endif }
static void show_grabbing_focus (GtkWidget *new_window) { const char *startup_id = NULL; guint32 timestamp = 0; gtk_widget_realize (new_window); startup_id = g_getenv ("DESKTOP_STARTUP_ID"); if (startup_id != NULL) { char *startup_id_str = g_strdup (startup_id); char *ts; ts = g_strrstr (startup_id_str, "_TIME"); if (ts != NULL) { ts = ts + 5; errno = 0; timestamp = strtoul (ts, NULL, 0); if ((errno == EINVAL) || (errno == ERANGE)) timestamp = 0; } g_free (startup_id_str); } if (timestamp == 0) timestamp = gdk_x11_get_server_time (new_window->window); gdk_x11_window_set_user_time (new_window->window, timestamp); gtk_window_present (GTK_WINDOW (new_window)); }
void show_force_quit_dialog (WnckWindow *win, Time timestamp) { decor_t *d = g_object_get_data (G_OBJECT (win), "decor"); GtkWidget *dialog; gchar *str, *tmp; const gchar *message; if (d->force_quit_dialog) return; tmp = g_markup_escape_text (wnck_window_get_name (win), -1); str = g_strdup_printf (_("The window \"%s\" is not responding."), tmp); g_free (tmp); message = _("Forcing this application to quit will cause you to lose any unsaved changes."); dialog = gtk_message_dialog_new_with_markup (NULL, 0, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, "<b>%s</b>\n\n%s", str, message); g_free (str); gtk_window_set_icon_name (GTK_WINDOW (dialog), "force-quit"); gtk_dialog_add_buttons (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_REJECT, _("_Force Quit"), GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT); g_signal_connect (G_OBJECT (dialog), "realize", G_CALLBACK (force_quit_dialog_realize), win); g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (force_quit_dialog_response), win); gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); gtk_widget_realize (dialog); gdk_x11_window_set_user_time (gtk_widget_get_window (dialog), timestamp); gtk_widget_show (dialog); d->force_quit_dialog = dialog; }
static GdkFilterReturn gdk_to_clutter_event_pump__ (GdkXEvent *xevent, GdkEvent *event, gpointer data) { GdkDisplay *display = gdk_display_get_default (); GdkWindow *gdk_win; XEvent *xev = (XEvent*) xevent; guint32 timestamp = 0; gdk_win = gdk_x11_window_foreign_new_for_display (display, xev->xany.window); if (!gdk_win) gdk_win = gdk_x11_window_foreign_new_for_display (display, GPOINTER_TO_INT (data)); /* * Ensure we update the user time on this window if the event * implies user action. */ switch (event->type) { case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: case GDK_BUTTON_RELEASE: timestamp = event->button.time; break; case GDK_MOTION_NOTIFY: timestamp = event->motion.time; break; case GDK_KEY_PRESS: case GDK_KEY_RELEASE: timestamp = event->key.time; break; default: ; } if (timestamp && gdk_win) gdk_x11_window_set_user_time (gdk_win, timestamp); switch (clutter_x11_handle_event (xev)) { default: case CLUTTER_X11_FILTER_CONTINUE: return GDK_FILTER_CONTINUE; case CLUTTER_X11_FILTER_TRANSLATE: return GDK_FILTER_TRANSLATE; case CLUTTER_X11_FILTER_REMOVE: return GDK_FILTER_REMOVE; } };
static void set_user_time (GdkWindow *window, GdkEvent *event) { g_return_if_fail (event != NULL); window = gdk_window_get_toplevel (event->any.window); g_return_if_fail (GDK_IS_WINDOW (window)); /* If an event doesn't have a valid timestamp, we shouldn't use it * to update the latest user interaction time. */ if (gdk_event_get_time (event) != GDK_CURRENT_TIME) gdk_x11_window_set_user_time (gdk_window_get_toplevel (window), gdk_event_get_time (event)); }
static PanelRunDialog * panel_run_dialog_new (GdkScreen *screen, GtkBuilder *gui, guint32 activate_time) { PanelRunDialog *dialog; dialog = g_new0 (PanelRunDialog, 1); dialog->run_dialog = PANEL_GTK_BUILDER_GET (gui, "panel_run_dialog"); g_signal_connect_swapped (dialog->run_dialog, "response", G_CALLBACK (panel_run_dialog_response), dialog); g_signal_connect_swapped (dialog->run_dialog, "destroy", G_CALLBACK (panel_run_dialog_destroy), dialog); dialog->run_button = PANEL_GTK_BUILDER_GET (gui, "run_button"); dialog->terminal_checkbox = PANEL_GTK_BUILDER_GET (gui, "terminal_checkbox"); dialog->settings = g_settings_new (PANEL_RUN_SCHEMA); panel_run_dialog_setup_pixmap (dialog, gui); panel_run_dialog_setup_entry (dialog, gui); panel_run_dialog_setup_file_button (dialog, gui); panel_run_dialog_setup_program_list (dialog, gui); panel_run_dialog_setup_list_expander (dialog, gui); panel_run_dialog_set_default_icon (dialog, FALSE); panel_run_dialog_update_content (dialog, panel_profile_get_show_program_list ()); gtk_widget_set_sensitive (dialog->run_button, FALSE); gtk_dialog_set_default_response (GTK_DIALOG (dialog->run_dialog), GTK_RESPONSE_OK); gtk_window_set_screen (GTK_WINDOW (dialog->run_dialog), screen); gtk_widget_grab_focus (dialog->combobox); gtk_widget_realize (dialog->run_dialog); gdk_x11_window_set_user_time (gtk_widget_get_window (dialog->run_dialog), activate_time); gtk_widget_show (dialog->run_dialog); return dialog; }
/* derived from tomboy */ static void _window_override_user_time (CsmFailWhaleDialog *window) { guint32 ev_time = gtk_get_current_event_time (); if (ev_time == 0) { gint ev_mask = gtk_widget_get_events (GTK_WIDGET (window)); if (!(ev_mask & GDK_PROPERTY_CHANGE_MASK)) { gtk_widget_add_events (GTK_WIDGET (window), GDK_PROPERTY_CHANGE_MASK); } /* * NOTE: Last resort for D-BUS or other non-interactive * openings. Causes roundtrip to server. Lame. */ ev_time = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window))); } gdk_x11_window_set_user_time (gtk_widget_get_window (GTK_WIDGET (window)), ev_time); }
static void ev_application_open_uri_in_window (EvApplication *application, const char *uri, EvWindow *ev_window, GdkScreen *screen, EvLinkDest *dest, EvWindowRunMode mode, const gchar *search_string, guint timestamp) { #ifdef GDK_WINDOWING_X11 GdkWindow *gdk_window; #endif if (screen) { ev_stock_icons_set_screen (screen); gtk_window_set_screen (GTK_WINDOW (ev_window), screen); } /* We need to load uri before showing the window, so we can restore window size without flickering */ ev_window_open_uri (ev_window, uri, dest, mode, search_string); if (!gtk_widget_get_realized (GTK_WIDGET (ev_window))) gtk_widget_realize (GTK_WIDGET (ev_window)); #ifdef GDK_WINDOWING_X11 gdk_window = gtk_widget_get_window (GTK_WIDGET (ev_window)); if (timestamp <= 0) timestamp = gdk_x11_get_server_time (gdk_window); gdk_x11_window_set_user_time (gdk_window, timestamp); gtk_window_present (GTK_WINDOW (ev_window)); #else gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp); #endif /* GDK_WINDOWING_X11 */ }
static VALUE gdkwin_set_user_time(VALUE self, VALUE time) { gdk_x11_window_set_user_time(_SELF(self), NUM2UINT(time)); return Qnil; }
/* serverside */ static void on_message_received (const char *message, gpointer data) { const PlumaEncoding *encoding = NULL; gchar **commands; gchar **params; gint workspace; gint viewport_x; gint viewport_y; gchar *display_name; gint screen_number; gint i; PlumaApp *app; PlumaWindow *window; GdkDisplay *display; GdkScreen *screen; g_return_if_fail (message != NULL); pluma_debug_message (DEBUG_APP, "Received message:\n%s\n", message); commands = g_strsplit (message, "\v", -1); /* header */ params = g_strsplit (commands[0], "\t", 6); startup_timestamp = atoi (params[0]); display_name = params[1]; screen_number = atoi (params[2]); workspace = atoi (params[3]); viewport_x = atoi (params[4]); viewport_y = atoi (params[5]); display = display_open_if_needed (display_name); if (display == NULL) { g_warning ("Could not open display %s\n", display_name); g_strfreev (params); goto out; } screen = gdk_display_get_screen (display, screen_number); g_strfreev (params); /* body */ for (i = 1; commands[i] != NULL; i++) { params = g_strsplit (commands[i], "\t", -1); if (strcmp (params[0], "NEW-WINDOW") == 0) { new_window_option = TRUE; } else if (strcmp (params[0], "NEW-DOCUMENT") == 0) { new_document_option = TRUE; } else if (strcmp (params[0], "OPEN-URIS") == 0) { gint n_uris, j; gchar **uris; line_position = atoi (params[1]); if (params[2] != '\0') encoding = pluma_encoding_get_from_charset (params[2]); n_uris = atoi (params[3]); uris = g_strsplit (params[4], " ", n_uris); for (j = 0; j < n_uris; j++) { GFile *file; file = g_file_new_for_uri (uris[j]); file_list = g_slist_prepend (file_list, file); } file_list = g_slist_reverse (file_list); /* the list takes ownerhip of the strings, * only free the array */ g_free (uris); } else { g_warning ("Unexpected bacon command"); } g_strfreev (params); } /* execute the commands */ app = pluma_app_get_default (); if (new_window_option) { window = pluma_app_create_window (app, screen); } else { /* get a window in the current workspace (if exists) and raise it */ window = _pluma_app_get_window_in_viewport (app, screen, workspace, viewport_x, viewport_y); } if (file_list != NULL) { _pluma_cmd_load_files_from_prompt (window, file_list, encoding, line_position); if (new_document_option) pluma_window_create_tab (window, TRUE); } else { PlumaDocument *doc; doc = pluma_window_get_active_document (window); if (doc == NULL || !pluma_document_is_untouched (doc) || new_document_option) pluma_window_create_tab (window, TRUE); } /* set the proper interaction time on the window. * Fall back to roundtripping to the X server when we * don't have the timestamp, e.g. when launched from * terminal. We also need to make sure that the window * has been realized otherwise it will not work. lame. */ if (!gtk_widget_get_realized (GTK_WIDGET (window))) gtk_widget_realize (GTK_WIDGET (window)); if (startup_timestamp <= 0) startup_timestamp = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window))); gdk_x11_window_set_user_time (gtk_widget_get_window (GTK_WIDGET (window)), startup_timestamp); gtk_window_present (GTK_WINDOW (window)); out: g_strfreev (commands); free_command_line_data (); }
gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpointer data) { gint fd, sock; gchar buf[BUFFER_LENGTH]; gchar *command = NULL; struct sockaddr_in caddr; socklen_t caddr_len = sizeof(caddr); GtkWidget *window = data; gboolean popup = FALSE; fd = g_io_channel_unix_get_fd(source); sock = accept(fd, (struct sockaddr *)&caddr, &caddr_len); /* first get the command */ while (socket_fd_gets(sock, buf, sizeof(buf)) != -1) { command = g_strdup(buf); geany_debug("Received IPC command from remote instance: %s", g_strstrip(command)); g_free(command); if (strncmp(buf, "open", 4) == 0) { cl_options.readonly = strncmp(buf+4, "ro", 2) == 0; /* open in readonly? */ while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.') { gsize buf_len = strlen(buf); /* remove trailing newline */ if (buf_len > 0 && buf[buf_len - 1] == '\n') buf[buf_len - 1] = '\0'; handle_input_filename(buf); } popup = TRUE; } else if (strncmp(buf, "doclist", 7) == 0) { gchar *doc_list = build_document_list(); if (!EMPTY(doc_list)) socket_fd_write_all(sock, doc_list, strlen(doc_list)); /* send ETX (end-of-text) so reader knows to stop reading */ socket_fd_write_all(sock, "\3", 1); g_free(doc_list); } else if (strncmp(buf, "line", 4) == 0) { while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.') { g_strstrip(buf); /* remove \n char */ /* on any error we get 0 which should be safe enough as fallback */ cl_options.goto_line = atoi(buf); } } else if (strncmp(buf, "column", 6) == 0) { while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.') { g_strstrip(buf); /* remove \n char */ /* on any error we get 0 which should be safe enough as fallback */ cl_options.goto_column = atoi(buf); } } #ifdef G_OS_WIN32 else if (strncmp(buf, "window", 6) == 0) { # if GTK_CHECK_VERSION(3, 0, 0) HWND hwnd = (HWND) gdk_win32_window_get_handle(gtk_widget_get_window(window)); # else HWND hwnd = (HWND) gdk_win32_drawable_get_handle( GDK_DRAWABLE(gtk_widget_get_window(window))); # endif socket_fd_write(sock, (gchar *)&hwnd, sizeof(hwnd)); } #endif } if (popup) { #ifdef GDK_WINDOWING_X11 GdkWindow *x11_window = gtk_widget_get_window(window); /* Set the proper interaction time on the window. This seems necessary to make * gtk_window_present() really bring the main window into the foreground on some * window managers like Gnome's metacity. * Code taken from Gedit. */ # if GTK_CHECK_VERSION(3, 0, 0) if (GDK_IS_X11_WINDOW(x11_window)) # endif { gdk_x11_window_set_user_time(x11_window, gdk_x11_get_server_time(x11_window)); } #endif gtk_window_present(GTK_WINDOW(window)); #ifdef G_OS_WIN32 gdk_window_show(gtk_widget_get_window(window)); #endif } socket_fd_close(sock); return TRUE; }
gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpointer data) { gint fd, sock; gchar buf[BUFFER_LENGTH]; struct sockaddr_in caddr; socklen_t caddr_len = sizeof(caddr); GtkWidget *window = data; gboolean popup = FALSE; fd = g_io_channel_unix_get_fd(source); sock = accept(fd, (struct sockaddr *)&caddr, &caddr_len); /* first get the command */ while (socket_fd_gets(sock, buf, sizeof(buf)) != -1) { if (strncmp(buf, "open", 4) == 0) { cl_options.readonly = strncmp(buf+4, "ro", 2) == 0; /* open in readonly? */ while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.') { handle_input_filename(g_strstrip(buf)); } popup = TRUE; } else if (strncmp(buf, "doclist", 7) == 0) { gchar *doc_list = build_document_list(); if (NZV(doc_list)) socket_fd_write_all(sock, doc_list, strlen(doc_list)); else /* send ETX (end-of-text) in case we have no open files, we must send anything * otherwise the client would hang on reading */ socket_fd_write_all(sock, "\3", 1); g_free(doc_list); } else if (strncmp(buf, "line", 4) == 0) { while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.') { g_strstrip(buf); /* remove \n char */ /* on any error we get 0 which should be safe enough as fallback */ cl_options.goto_line = atoi(buf); } } else if (strncmp(buf, "column", 6) == 0) { while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.') { g_strstrip(buf); /* remove \n char */ /* on any error we get 0 which should be safe enough as fallback */ cl_options.goto_column = atoi(buf); } } #ifdef G_OS_WIN32 else if (strncmp(buf, "window", 6) == 0) { HWND hwnd = (HWND) gdk_win32_drawable_get_handle( GDK_DRAWABLE(gtk_widget_get_window(window))); socket_fd_write(sock, (gchar *)&hwnd, sizeof(hwnd)); } #endif } if (popup) { #ifdef GDK_WINDOWING_X11 /* Set the proper interaction time on the window. This seems necessary to make * gtk_window_present() really bring the main window into the foreground on some * window managers like Gnome's metacity. * Code taken from Gedit. */ gdk_x11_window_set_user_time(gtk_widget_get_window(window), gdk_x11_get_server_time(gtk_widget_get_window(window))); #endif gtk_window_present(GTK_WINDOW(window)); #ifdef G_OS_WIN32 gdk_window_show(gtk_widget_get_window(window)); #endif } socket_fd_close(sock); return TRUE; }
/** * @force_hide: This option is used by the auto hide feature, so we can ignore the checks to focus tilda instead * of pulling up. */ void pull (struct tilda_window_ *tw, enum pull_state state, gboolean force_hide) { DEBUG_FUNCTION ("pull"); DEBUG_ASSERT (tw != NULL); DEBUG_ASSERT (state == PULL_UP || state == PULL_DOWN || state == PULL_TOGGLE); gint i; gboolean needsFocus = !tw->focus_loss_on_keypress && !gtk_window_is_active(GTK_WINDOW(tw->window)) && !force_hide && !tw->hide_non_focused; if (tw->current_state == DOWN && needsFocus) { /** * See tilda_window.c in focus_out_event_cb for an explanation about focus_loss_on_keypress * This conditional branch will only focus tilda but it does not actually pull the window up. */ TRACE (g_print("Tilda window not focused but visible\n")); gdk_x11_window_set_user_time(gtk_widget_get_window(tw->window), tomboy_keybinder_get_current_event_time()); tilda_window_set_active(tw); } else if (tw->current_state == UP && state != PULL_UP) { /* Keep things here just like they are. If you use gtk_window_present() here, you * will introduce some weird graphical glitches. Also, calling gtk_window_move() * before showing the window avoids yet more glitches. You should probably not use * gtk_window_show_all() here, as it takes a long time to execute. * * Overriding the user time here seems to work a lot better than calling * gtk_window_present_with_time() here, or at the end of the function. I have * no idea why, they should do the same thing. */ gdk_x11_window_set_user_time (gtk_widget_get_window (tw->window), tomboy_keybinder_get_current_event_time()); gtk_window_move (GTK_WINDOW(tw->window), config_getint ("x_pos"), config_getint ("y_pos")); gtk_widget_show (GTK_WIDGET(tw->window)); /* Nasty code to make metacity behave. Starting at metacity-2.22 they "fixed" the * focus stealing prevention to make the old _NET_WM_USER_TIME hack * not work anymore. This is working for now... */ tilda_window_set_active (tw); /* The window should maintain its properties when it is merely hidden, but it does * not. If you delete the following call, the window will not remain visible * on all workspaces after pull()ing it up and down a number of times. * * Note that the "Always on top" property doesn't seem to go away, only this * property (Show on all desktops) does... */ if (config_getbool ("pinned")) gtk_window_stick (GTK_WINDOW (tw->window)); if (config_getbool ("animation")) { for (i=0; i<16; i++) { gtk_window_move (GTK_WINDOW(tw->window), posIV[2][i], posIV[0][i]); gtk_window_resize (GTK_WINDOW(tw->window), posIV[3][i], posIV[1][i]); process_all_pending_gtk_events (); g_usleep (config_getint ("slide_sleep_usec")); } } debug_printf ("pull(): MOVED DOWN\n"); tw->current_state = DOWN; } else if (state != PULL_DOWN) { if (config_getbool ("animation")) { for (i=15; i>=0; i--) { gtk_window_move (GTK_WINDOW(tw->window), posIV[2][i], posIV[0][i]); gtk_window_resize (GTK_WINDOW(tw->window), posIV[3][i], posIV[1][i]); process_all_pending_gtk_events (); g_usleep (config_getint ("slide_sleep_usec")); } } /* All we have to do at this point is hide the window. * Case 1 - Animation on: The window has shrunk, just hide it * Case 2 - Animation off: Just hide the window */ gtk_widget_hide (GTK_WIDGET(tw->window)); debug_printf ("pull(): MOVED UP\n"); tw->current_state = UP; } }