/* We should probably experiment some more with this. * Right now the rendered icon is pretty good for most * themes. However, the icon is slightly large for themes * with large toolbar icons. */ static GdkPixbuf * new_pixbuf_from_widget (GtkWidget *widget) { GtkWidget *window; GdkPixbuf *pixbuf; gint icon_height; GdkScreen *screen; screen = gtk_widget_get_screen (widget); if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen), GTK_ICON_SIZE_LARGE_TOOLBAR, NULL, &icon_height)) { icon_height = DEFAULT_ICON_HEIGHT; } window = gtk_offscreen_window_new (); /* Set the width to -1 as we want the separator to be as thin as possible. */ gtk_widget_set_size_request (widget, -1, icon_height); gtk_container_add (GTK_CONTAINER (window), widget); gtk_widget_show_all (window); /* Process the waiting events to have the widget actually drawn */ gdk_window_process_updates (gtk_widget_get_window (window), TRUE); pixbuf = gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (window)); gtk_widget_destroy (window); return pixbuf; }
static void ensure_icon_size (GtkIconHelper *self, GtkStyleContext *context, gint *width_out, gint *height_out) { gint width, height; GtkSettings *settings; GdkScreen *screen; screen = gtk_style_context_get_screen (context); settings = gtk_settings_get_for_screen (screen); if (self->priv->pixel_size != -1) { width = height = self->priv->pixel_size; } else if (!gtk_icon_size_lookup_for_settings (settings, self->priv->icon_size, &width, &height)) { if (self->priv->icon_size == GTK_ICON_SIZE_INVALID) { width = height = 0; } else { g_warning ("Invalid icon size %d\n", self->priv->icon_size); width = height = 24; } } *width_out = width; *height_out = height; }
int GtkClickCounter::clickCountForGdkButtonEvent(GtkWidget* widget, GdkEventButton* buttonEvent) { gint doubleClickDistance = 250; gint doubleClickTime = 5; GtkSettings* settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget)); g_object_get(settings, "gtk-double-click-distance", &doubleClickDistance, "gtk-double-click-time", &doubleClickTime, NULL); // GTK+ only counts up to triple clicks, but WebCore wants to know about // quadruple clicks, quintuple clicks, ad infinitum. Here, we replicate the // GDK logic for counting clicks. GdkEvent* event(reinterpret_cast<GdkEvent*>(buttonEvent)); guint32 eventTime = getEventTime(event); if ((event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) || ((abs(buttonEvent->x - m_previousClickPoint.x()) < doubleClickDistance) && (abs(buttonEvent->y - m_previousClickPoint.y()) < doubleClickDistance) && (eventTime - m_previousClickTime < static_cast<guint>(doubleClickTime)) && (buttonEvent->button == m_previousClickButton))) m_currentClickCount++; else m_currentClickCount = 1; gdouble x, y; gdk_event_get_coords(event, &x, &y); m_previousClickPoint = IntPoint(x, y); m_previousClickButton = buttonEvent->button; m_previousClickTime = eventTime; return m_currentClickCount; }
/**************************************************************************** Update a font option which is not attached to a widget. ****************************************************************************/ void gui_update_font_full(const char *font_name, const char *font_value, GtkStyle **pstyle) { GtkSettings *settings; GdkScreen *screen; GtkStyle *style; char buf[64]; gui_update_font(font_name, font_value); screen = gdk_screen_get_default(); settings = gtk_settings_get_for_screen(screen); fc_snprintf(buf, sizeof(buf), "Freeciv*.%s", font_name); style = gtk_rc_get_style_by_paths(settings, buf, NULL, G_TYPE_NONE); if (style) { g_object_ref(style); } else { style = gtk_style_new(); } if (*pstyle) { g_object_unref(*pstyle); } *pstyle = style; }
static void set_floating_bar_status (NemoWindowSlot *slot, const gchar *status) { GtkSettings *settings; gint double_click_time; SetStatusData *status_data; if (slot->set_status_timeout_id != 0) { g_source_remove (slot->set_status_timeout_id); slot->set_status_timeout_id = 0; } settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (slot->content_view))); g_object_get (settings, "gtk-double-click-time", &double_click_time, NULL); status_data = g_slice_new0 (SetStatusData); status_data->status = g_strdup (status); status_data->slot = slot; /* waiting for half of the double-click-time before setting * the status seems to be a good approximation of not setting it * too often and not delaying the statusbar too much. */ slot->set_status_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) (double_click_time / 2), set_status_timeout_cb, status_data, set_status_data_free); }
static void menus_can_change_accels (GimpGuiConfig *config) { g_object_set (gtk_settings_get_for_screen (gdk_screen_get_default ()), "gtk-can-change-accels", config->can_change_accels, NULL); }
JNIEXPORT jlong JNICALL Java_org_gnome_gtk_GtkSettings_gtk_1settings_1get_1for_1screen ( JNIEnv* env, jclass cls, jlong _screen ) { GtkSettings* result; jlong _result; GdkScreen* screen; // convert parameter screen screen = (GdkScreen*) _screen; // call function result = gtk_settings_get_for_screen(screen); // cleanup parameter screen // translate return value to JNI type _result = (jlong) result; // cleanup return value if (result != NULL) { bindings_java_memory_cleanup((GObject*)result, FALSE); } // and finally return _result; }
void nautilus_window_finalize_menus (NautilusWindow *window) { if (window->details->app_menu_visibility_id != 0) { g_signal_handler_disconnect (gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))), window->details->app_menu_visibility_id); window->details->app_menu_visibility_id = 0; } }
/** * gtk_clutter_texture_set_from_icon_name: * @texture: a #GtkClutterTexture * @widget: (allow-none): a #GtkWidget or %NULL * @icon_name: the name of the icon * @icon_size: the icon size or -1 * @error: a return location for errors, or %NULL * * Sets the contents of @texture using the @icon_name from the * current icon theme. * * Return value: %TRUE on success, %FALSE on failure * * Since: 1.0 */ gboolean gtk_clutter_texture_set_from_icon_name (GtkClutterTexture *texture, GtkWidget *widget, const gchar *icon_name, GtkIconSize icon_size, GError **error) { GError *local_error = NULL; GtkSettings *settings; GtkIconTheme *icon_theme; gboolean returnval; gint width, height; GdkPixbuf *pixbuf; g_return_val_if_fail (CLUTTER_IS_TEXTURE (texture), FALSE); g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); g_return_val_if_fail (icon_name != NULL, FALSE); g_return_val_if_fail ((icon_size > GTK_ICON_SIZE_INVALID) || (icon_size == -1), FALSE); if (widget && gtk_widget_has_screen (widget)) { GdkScreen *screen; screen = gtk_widget_get_screen (widget); settings = gtk_settings_get_for_screen (screen); icon_theme = gtk_icon_theme_get_for_screen (screen); } else { settings = gtk_settings_get_default (); icon_theme = gtk_icon_theme_get_default (); } G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (icon_size == -1 || !gtk_icon_size_lookup_for_settings (settings, icon_size, &width, &height)) { width = height = 48; } G_GNUC_END_IGNORE_DEPRECATIONS pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, MIN (width, height), 0, &local_error); if (local_error) { g_propagate_error (error, local_error); return FALSE; } returnval = gtk_clutter_texture_set_from_pixbuf (texture, pixbuf, error); g_object_unref (pixbuf); return returnval; }
static void event_box_realize_cb (GtkWidget *widget, GtkImage *icon) { GtkImageType type; set_drag_cursor (widget); type = gtk_image_get_storage_type (icon); if (type == GTK_IMAGE_STOCK) { gchar *stock_id; GdkPixbuf *pixbuf; gtk_image_get_stock (icon, &stock_id, NULL); pixbuf = gtk_widget_render_icon (widget, stock_id, GTK_ICON_SIZE_LARGE_TOOLBAR, NULL); gtk_drag_source_set_icon_pixbuf (widget, pixbuf); g_object_unref (pixbuf); } else if (type == GTK_IMAGE_ICON_NAME) { const gchar *icon_name; GdkScreen *screen; GtkIconTheme *icon_theme; GtkSettings *settings; gint width, height; GdkPixbuf *pixbuf; gtk_image_get_icon_name (icon, &icon_name, NULL); screen = gtk_widget_get_screen (widget); icon_theme = gtk_icon_theme_get_for_screen (screen); settings = gtk_settings_get_for_screen (screen); if (!gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_LARGE_TOOLBAR, &width, &height)) { width = height = 24; } pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, MIN (width, height), 0, NULL); if (G_UNLIKELY (!pixbuf)) return; gtk_drag_source_set_icon_pixbuf (widget, pixbuf); g_object_unref (pixbuf); } else if (type == GTK_IMAGE_PIXBUF) { GdkPixbuf *pixbuf = gtk_image_get_pixbuf (icon); gtk_drag_source_set_icon_pixbuf (widget, pixbuf); } }
static void tooltips_enable_cb (GtkCheckMenuItem *item, gpointer data) { gboolean enable; GdkScreen *screen; GtkSettings *settings; screen = gtk_window_get_screen(GTK_WINDOW(main_window)); settings = gtk_settings_get_for_screen(screen); enable = gtk_check_menu_item_get_active(item); g_object_set(settings, "gtk-enable-tooltips", enable, NULL); }
/** * fm_widget_menu_fix_tooltips * @menu: a #GtkMenu instance * * Fix on GTK bug: it does not assign tooltips of menu items from * appropriate #GtkAction objects. This API assigns them instead. * * Since: 1.2.0 */ void fm_widget_menu_fix_tooltips(GtkMenu *menu) { GtkWidget *parent; GtkSettings *settings; gboolean tooltips_enabled; g_return_if_fail(GTK_IS_MENU(menu)); parent = gtk_menu_get_attach_widget(menu); settings = parent ? gtk_settings_get_for_screen(gtk_widget_get_screen(parent)) : gtk_settings_get_default(); g_object_get(G_OBJECT(settings), "gtk-enable-tooltips", &tooltips_enabled, NULL); if(tooltips_enabled) assign_tooltips_from_actions(GTK_WIDGET(menu)); }
void gtk_icon_entry_set_icon_from_gicon (const GtkIconEntry *entry, GtkIconEntryPosition icon_pos, GIcon *icon) { GdkPixbuf *pixbuf = NULL; GtkIconEntryPrivate *priv; EntryIconInfo *icon_info; GdkScreen *screen; GtkIconTheme *icon_theme; GtkSettings *settings; gint width, height; GError *error = NULL; GtkIconInfo *info; priv = GTK_ICON_ENTRY_GET_PRIVATE (entry); icon_info = &priv->icons[icon_pos]; screen = gtk_widget_get_screen (GTK_WIDGET (entry)); icon_theme = gtk_icon_theme_get_for_screen (screen); settings = gtk_settings_get_for_screen (screen); if (icon != NULL) { gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height); #if #GTK_CHECK_VERSION (2, 14, 0) info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, MIN (width, height), 0); #else info = NULL; #endif pixbuf = gtk_icon_info_load_icon (info, &error); if (pixbuf == NULL) { g_error_free (error); pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry), GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_MENU, NULL); } } gtk_icon_entry_set_icon_internal ((GtkIconEntry*)entry, icon_pos, pixbuf); }
int main (int argc, char **argv) { GObject *desktop; gchar *gtkrc = NULL; g_thread_init (NULL); setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Read the maemo-af-desktop gtkrc file */ gtkrc = g_build_filename (g_get_home_dir (), OSSO_USER_DIR, HILDON_DESKTOP_GTKRC, NULL); if (gtkrc && g_file_test ((gtkrc), G_FILE_TEST_EXISTS)) { gtk_rc_add_default_file (gtkrc); } g_free (gtkrc); /* If gtk_init was called already (maemo-launcher is used), * re-parse the gtkrc to include the maemo-af-desktop specific one */ if (gdk_screen_get_default ()) { gtk_rc_reparse_all_for_settings ( gtk_settings_get_for_screen (gdk_screen_get_default ()), TRUE); } gtk_init (&argc, &argv); gnome_vfs_init (); signal (SIGTERM, signal_handler); desktop = hd_desktop_new (); hd_desktop_run (HD_DESKTOP (desktop)); gtk_main (); return 0; }
/** * gtk_icon_entry_set_icon_from_icon_name * @entry: A #GtkIconEntry; * @icon_pos: The position at which to set the icon * @icon_name: An icon name * * Sets the icon shown in the entry at the specified position from the current * icon theme. If the icon name isn't known, a "broken image" icon will be * displayed instead. If the current icon theme is changed, the icon will be * updated appropriately. */ void gtk_icon_entry_set_icon_from_icon_name (GtkIconEntry *entry, GtkIconEntryPosition icon_pos, const gchar *icon_name) { GdkPixbuf *pixbuf = NULL; EntryIconInfo *icon_info; GtkIconEntryPrivate *priv; GdkScreen *screen; GtkIconTheme *icon_theme; GtkSettings *settings; gint width, height; GError *error = NULL; g_return_if_fail (entry != NULL); g_return_if_fail (GTK_IS_ICON_ENTRY (entry)); g_return_if_fail (IS_VALID_ICON_ENTRY_POSITION (icon_pos)); priv = GTK_ICON_ENTRY_GET_PRIVATE (entry); icon_info = &priv->icons[icon_pos]; screen = gtk_widget_get_screen (GTK_WIDGET (entry)); icon_theme = gtk_icon_theme_get_for_screen (screen); settings = gtk_settings_get_for_screen (screen); if (icon_name != NULL) { gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height); pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, MIN (width, height), 0, &error); if (pixbuf == NULL) { g_error_free (error); pixbuf = gtk_widget_render_icon (GTK_WIDGET (entry), GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_MENU, NULL); } } gtk_icon_entry_set_icon_internal (entry, icon_pos, pixbuf); }
gboolean generic_dialog_get_alternative_button_order(GtkWidget *widget) { GtkSettings *settings; GObjectClass *klass; gboolean alternative_order = FALSE; settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget)); klass = G_OBJECT_CLASS(GTK_SETTINGS_GET_CLASS(settings)); if (g_object_class_find_property(klass, "gtk-alternative-button-order")) { g_object_get(settings, "gtk-alternative-button-order", &alternative_order, NULL); } return alternative_order; }
void VNCCanvas::ungrab_keyboard() { #ifdef __WXGTK__ // ungrab gdk_keyboard_ungrab(GDK_CURRENT_TIME); // restore to saved values GtkSettings *settings = gtk_settings_get_for_screen(gdk_screen_get_default()); g_object_set(settings, "gtk-enable-mnemonics", saved_enable_mnemonics, NULL); g_object_set(settings, "gtk-enable-accels", saved_enable_accels, NULL); g_object_set(settings, "gtk-menu-bar-accel", saved_menubar_accel, NULL); #endif keyboard_grabbed = false; wxLogDebug(wxT("VNCCanvas %p: ungrabbed keyboard"), this); }
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; }
void gimp_icons_set_icon_theme (GFile *path) { gchar *icon_theme_name; GFile *search_path; g_return_if_fail (path == NULL || G_IS_FILE (path)); if (path) path = g_object_ref (path); else path = gimp_data_directory_file ("icons", GIMP_DEFAULT_ICON_THEME, NULL); search_path = g_file_get_parent (path); icon_theme_name = g_file_get_basename (path); if (gimp_icons_sanity_check (search_path, "hicolor") && gimp_icons_sanity_check (search_path, icon_theme_name)) { if (icon_theme_path) { /* this is an icon theme change */ gimp_icons_change_icon_theme (search_path); if (! g_file_equal (icon_theme_path, path)) { g_object_unref (icon_theme_path); icon_theme_path = g_object_ref (path); } g_object_set (gtk_settings_get_for_screen (gdk_screen_get_default ()), "gtk-icon-theme-name", icon_theme_name, NULL); } else { /* this is the first call upon initialization */ icon_theme_path = g_object_ref (path); } } g_free (icon_theme_name); g_object_unref (search_path); g_object_unref (path); }
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); }
static void nautilus_window_menus_set_visibility_for_app_menu (NautilusWindow *window) { const gchar *action_name; gboolean shows_app_menu; GtkSettings *settings; GtkAction *action; gint idx; settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window))); g_object_get (settings, "gtk-shell-shows-app-menu", &shows_app_menu, NULL); for (idx = 0; idx < G_N_ELEMENTS (app_actions); idx++) { action_name = app_actions[idx]; action = gtk_action_group_get_action (window->details->main_action_group, action_name); gtk_action_set_visible (action, !shows_app_menu); } }
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; }
/** * gtk_timeline_start: * @timeline: A #GtkTimeline * * Runs the timeline from the current frame. **/ void _gtk_timeline_start (GtkTimeline *timeline) { GtkTimelinePriv *priv; GtkSettings *settings; gboolean enable_animations = FALSE; g_return_if_fail (GTK_IS_TIMELINE (timeline)); priv = timeline->priv; if (!priv->source_id) { if (priv->timer) g_timer_continue (priv->timer); else priv->timer = g_timer_new (); /* sanity check */ g_assert (priv->fps > 0); if (priv->screen) { settings = gtk_settings_get_for_screen (priv->screen); g_object_get (settings, "gtk-enable-animations", &enable_animations, NULL); } priv->animations_enabled = enable_animations; g_signal_emit (timeline, signals [STARTED], 0); if (enable_animations) priv->source_id = gdk_threads_add_timeout (FRAME_INTERVAL (priv->fps), (GSourceFunc) gtk_timeline_run_frame, timeline); else priv->source_id = gdk_threads_add_idle ((GSourceFunc) gtk_timeline_run_frame, timeline); } }
void VNCCanvas::grab_keyboard() { if(!keyboard_grabbed) { #ifdef __WXGTK__ // grab gdk_keyboard_grab(GetHandle()->window, True, GDK_CURRENT_TIME); // save previous settings GtkSettings *settings = gtk_settings_get_for_screen(gdk_screen_get_default()); g_object_get(settings, "gtk-enable-mnemonics", &saved_enable_mnemonics, NULL); g_object_get(settings, "gtk-enable-accels", &saved_enable_accels, NULL); g_object_get(settings, "gtk-menu-bar-accel", &saved_menubar_accel, NULL); // and disable keyboard shortcuts g_object_set(settings, "gtk-enable-mnemonics", false, NULL); g_object_set(settings, "gtk-enable-accels", false, NULL); g_object_set(settings, "gtk-menu-bar-accel", NULL, NULL); #endif keyboard_grabbed = true; wxLogDebug(wxT("VNCCanvas %p: grabbed keyboard"), this); } }
static void menu_style_set_cb (GtkWidget *menu, GtkStyle *old_style, ShellStatusMenu *status) { ShellStatusMenuPrivate *priv = status->priv; GtkSettings *settings; int width; int height; priv->icon_size = gtk_icon_size_from_name ("panel-menu"); if (priv->icon_size == GTK_ICON_SIZE_INVALID) priv->icon_size = gtk_icon_size_register ("panel-menu", 24, 24); if (gtk_widget_has_screen (menu)) settings = gtk_settings_get_for_screen (gtk_widget_get_screen (menu)); else settings = gtk_settings_get_default (); if (!gtk_icon_size_lookup_for_settings (settings, priv->icon_size, &width, &height)) priv->pixel_size = -1; else priv->pixel_size = MAX(width, height); }
// 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(); }
/************************************************************************** Creates a new dialog. It will be a tab or a window depending on the current user setting of 'gui_gtk3_enable_tabs'. Sets pdlg to point to the dialog once it is create, Zeroes pdlg on dialog destruction. user_data will be passed through response function check_top indicates if the layout deision should depend on the parent. **************************************************************************/ void gui_dialog_new(struct gui_dialog **pdlg, GtkNotebook *notebook, gpointer user_data, bool check_top) { struct gui_dialog *dlg; GtkWidget *vbox, *action_area; static int dialog_id_counter; dlg = fc_malloc(sizeof(*dlg)); dialog_list = g_list_prepend(dialog_list, dlg); dlg->source = pdlg; *pdlg = dlg; dlg->user_data = user_data; dlg->title = NULL; dlg->default_width = 200; dlg->default_height = 300; if (gui_gtk3_enable_tabs) { dlg->type = GUI_DIALOG_TAB; } else { dlg->type = GUI_DIALOG_WINDOW; } if (!gui_action) { gui_action = gtk_size_group_new(GTK_SIZE_GROUP_VERTICAL); } dlg->gui_button = gtk_size_group_new(GTK_SIZE_GROUP_BOTH); vbox = gtk_grid_new(); action_area = gtk_grid_new(); gtk_grid_set_row_spacing(GTK_GRID(action_area), 4); gtk_grid_set_column_spacing(GTK_GRID(action_area), 4); if (gui_gtk3_enable_tabs && (check_top && notebook != GTK_NOTEBOOK(top_notebook)) && !gui_gtk3_small_display_layout) { /* We expect this to be short (as opposed to tall); maximise usable * height by putting buttons down the right hand side */ gtk_orientable_set_orientation(GTK_ORIENTABLE(action_area), GTK_ORIENTATION_VERTICAL); } else { /* We expect this to be reasonably tall; maximise usable width by * putting buttons along the bottom */ gtk_orientable_set_orientation(GTK_ORIENTABLE(vbox), GTK_ORIENTATION_VERTICAL); } gtk_widget_show(vbox); gtk_container_add(GTK_CONTAINER(vbox), action_area); gtk_widget_show(action_area); gtk_container_set_border_width(GTK_CONTAINER(vbox), 2); gtk_container_set_border_width(GTK_CONTAINER(action_area), 2); switch (dlg->type) { case GUI_DIALOG_WINDOW: { GtkWidget *window; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_name(window, "Freeciv"); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_MOUSE); setup_dialog(window, toplevel); gtk_container_add(GTK_CONTAINER(window), vbox); dlg->v.window = window; g_signal_connect(window, "delete_event", G_CALLBACK(gui_dialog_delete_handler), dlg); } break; case GUI_DIALOG_TAB: { GtkWidget *hbox, *label, *image, *button, *event_box; gint w, h; gchar *buf; gtk_icon_size_lookup_for_settings( gtk_settings_get_for_screen(gtk_widget_get_screen(vbox)), GTK_ICON_SIZE_MENU, &w, &h); hbox = gtk_grid_new(); label = gtk_label_new(NULL); gtk_widget_set_halign(label, GTK_ALIGN_START); gtk_widget_set_valign(label, GTK_ALIGN_CENTER); gtk_widget_set_margin_left(label, 4); gtk_widget_set_margin_right(label, 4); gtk_widget_set_margin_top(label, 0); gtk_widget_set_margin_bottom(label, 0); gtk_container_add(GTK_CONTAINER(hbox), label); button = gtk_button_new(); gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); g_signal_connect_swapped(button, "clicked", G_CALLBACK(gui_dialog_delete_tab_handler), dlg); buf = g_strdup_printf(_("Close Tab:\n%s"), _("Ctrl+W")); gtk_widget_set_tooltip_text(button, buf); g_free(buf); image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); gtk_widget_set_margin_left(image, 0); gtk_widget_set_margin_right(image, 0); gtk_widget_set_margin_top(image, 0); gtk_widget_set_margin_bottom(image, 0); gtk_button_set_image(GTK_BUTTON(button), image); gtk_container_add(GTK_CONTAINER(hbox), button); gtk_widget_show_all(hbox); event_box = gtk_event_box_new(); gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE); gtk_container_add(GTK_CONTAINER(event_box), hbox); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, event_box); dlg->v.tab.handler_id = g_signal_connect(notebook, "switch-page", G_CALLBACK(gui_dialog_switch_page_handler), dlg); dlg->v.tab.child = vbox; dlg->v.tab.label = label; dlg->v.tab.notebook = GTK_WIDGET(notebook); gtk_widget_add_events(event_box, GDK_BUTTON2_MOTION_MASK); g_signal_connect(event_box, "button-press-event", G_CALLBACK(click_on_tab_callback), dlg); } break; } dlg->vbox = vbox; dlg->action_area = action_area; dlg->response_callback = gui_dialog_destroyed; dlg->id = dialog_id_counter; dialog_id_counter++; dlg->return_dialog_id = -1; g_signal_connect(vbox, "destroy", G_CALLBACK(gui_dialog_destroy_handler), dlg); g_signal_connect(vbox, "key_press_event", G_CALLBACK(gui_dialog_key_press_handler), dlg); g_object_set_data(G_OBJECT(vbox), "gui-dialog-data", dlg); }
static void configure_item_cursor (GtkToolItem *item, EggEditableToolbar *etoolbar) { EggEditableToolbarPrivate *priv = etoolbar->priv; GtkWidget *widget = GTK_WIDGET (item); if (gtk_widget_get_window (widget) != NULL) { if (priv->edit_mode > 0) { GdkCursor *cursor; GdkScreen *screen; GdkPixbuf *pixbuf = NULL; screen = gtk_widget_get_screen (GTK_WIDGET (etoolbar)); cursor = gdk_cursor_new_for_display (gdk_screen_get_display (screen), GDK_HAND2); gdk_window_set_cursor (gtk_widget_get_window (widget), cursor); gdk_cursor_unref (cursor); gtk_drag_source_set (widget, GDK_BUTTON1_MASK, dest_drag_types, G_N_ELEMENTS (dest_drag_types), GDK_ACTION_MOVE); if (GTK_IS_SEPARATOR_TOOL_ITEM (item)) { pixbuf = new_separator_pixbuf (); } else { char *icon_name=NULL; char *stock_id=NULL; GtkAction *action; char *name; name = g_object_get_data (G_OBJECT (widget), EGG_ITEM_NAME); action = name ? find_action (etoolbar, name) : NULL; if (action) { g_object_get (action, "icon-name", &icon_name, "stock-id", &stock_id, NULL); } if (icon_name) { GdkScreen *screen; GtkIconTheme *icon_theme; GtkSettings *settings; gint width, height; screen = gtk_widget_get_screen (widget); icon_theme = gtk_icon_theme_get_for_screen (screen); settings = gtk_settings_get_for_screen (screen); if (!gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_LARGE_TOOLBAR, &width, &height)) { width = height = 24; } pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name, MIN (width, height), 0, NULL); } else if (stock_id) { pixbuf = gtk_widget_render_icon (widget, stock_id, GTK_ICON_SIZE_LARGE_TOOLBAR, NULL); } g_free (icon_name); g_free (stock_id); } if (G_UNLIKELY (!pixbuf)) { return; } gtk_drag_source_set_icon_pixbuf (widget, pixbuf); g_object_unref (pixbuf); } else { gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET(item)), NULL); } } }
char * panel_xdg_icon_name_from_icon_path (const char *path, GdkScreen *screen) { GtkIconTheme *theme; GtkSettings *settings; char *theme_name; char *icon; char **paths; int n_paths; int i; GFile *file; /* we look if the icon comes from the current icon theme */ if (!screen) screen = gdk_screen_get_default (); settings = gtk_settings_get_for_screen (screen); g_object_get (settings, "gtk-icon-theme-name", &theme_name, NULL); theme = gtk_icon_theme_get_for_screen (screen); gtk_icon_theme_get_search_path (theme, &paths, &n_paths); file = g_file_new_for_path (path); icon = NULL; for (i = 0; i < n_paths; i++) { GFile *parent; char *basename; parent = g_file_new_for_path (paths[i]); if (!g_file_has_prefix (file, parent)) { g_object_unref (parent); continue; } basename = g_file_get_basename (parent); if (g_strcmp0 (basename, "pixmaps") == 0) { char *relative_path; relative_path = g_file_get_relative_path (parent, file); /* if the icon is in a subdir of pixmaps, then it's not * a real icon name */ if (!strchr (relative_path, G_DIR_SEPARATOR)) icon = panel_xdg_icon_remove_extension (relative_path); g_free (relative_path); } else { /* real icon theme; but is it the current one? */ GFile *theme_dir; gboolean current; theme_dir = g_file_get_child (parent, theme_name); current = FALSE; if (g_file_has_prefix (file, theme_dir)) { /* it's the current one */ current = TRUE; } else { /* it's the default one */ g_object_unref (theme_dir); theme_dir = g_file_get_child (parent, DEFAULT_THEME_NAME); current = g_file_has_prefix (file, theme_dir); } g_object_unref (theme_dir); if (current) { char *buffer; buffer = g_file_get_basename (file); icon = panel_xdg_icon_remove_extension (buffer); g_free (buffer); } } g_free (basename); g_object_unref (parent); break; } g_object_unref (file); g_free (theme_name); return icon; }
static EphySpinnerImages * ephy_spinner_images_load (GdkScreen *screen, GtkIconTheme *icon_theme, GtkIconSize icon_size) { EphySpinnerImages *images; GdkPixbuf *icon_pixbuf, *pixbuf; GtkIconInfo *icon_info = NULL; int grid_width, grid_height, x, y, requested_size, size, isw, ish, n; const char *icon; GSList *list = NULL, *l; LOG ("EphySpinnerCacheData loading for screen %p at size %d", screen, icon_size); START_PROFILER ("loading spinner animation") if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_for_screen (screen), icon_size, &isw, &ish)) goto loser; requested_size = MAX (ish, isw); /* Load the animation. The 'rest icon' is the 0th frame */ icon_info = gtk_icon_theme_lookup_icon (icon_theme, SPINNER_ICON_NAME, requested_size, 0); if (icon_info == NULL) { g_warning ("Throbber animation not found"); /* If the icon naming spec compliant name wasn't found, try the old name */ icon_info = gtk_icon_theme_lookup_icon (icon_theme, SPINNER_FALLBACK_ICON_NAME, requested_size, 0); if (icon_info == NULL) { g_warning ("Throbber fallback animation not found either"); goto loser; } } g_assert (icon_info != NULL); size = gtk_icon_info_get_base_size (icon_info); icon = gtk_icon_info_get_filename (icon_info); if (icon == NULL) goto loser; icon_pixbuf = gdk_pixbuf_new_from_file (icon, NULL); gtk_icon_info_free (icon_info); icon_info = NULL; if (icon_pixbuf == NULL) { g_warning ("Could not load the spinner file"); goto loser; } grid_width = gdk_pixbuf_get_width (icon_pixbuf); grid_height = gdk_pixbuf_get_height (icon_pixbuf); n = 0; for (y = 0; y < grid_height; y += size) { for (x = 0; x < grid_width ; x += size) { pixbuf = extract_frame (icon_pixbuf, x, y, size); if (pixbuf) { list = g_slist_prepend (list, pixbuf); ++n; } else { g_warning ("Cannot extract frame (%d, %d) from the grid\n", x, y); } } } g_object_unref (icon_pixbuf); if (list == NULL) goto loser; g_assert (n > 0); if (size > requested_size) { for (l = list; l != NULL; l = l->next) { l->data = scale_to_size (l->data, isw, ish); } } /* Now we've successfully got all the data */ images = g_new (EphySpinnerImages, 1); images->ref_count = 1; images->size = icon_size; images->width = images->height = requested_size; images->n_animation_pixbufs = n; images->animation_pixbufs = g_new (GdkPixbuf *, n); for (l = list; l != NULL; l = l->next) { g_assert (l->data != NULL); images->animation_pixbufs[--n] = l->data; } g_assert (n == 0); g_slist_free (list); STOP_PROFILER ("loading spinner animation") return images; loser: if (icon_info) { gtk_icon_info_free (icon_info); } g_slist_foreach (list, (GFunc) g_object_unref, NULL); STOP_PROFILER ("loading spinner animation") return NULL; }