[PATCH] pinentry: More gseal/gtk3 compatibility in the gtk+3 UI.
Neal H. Walfield
neal at walfield.org
Mon May 18 11:57:58 CEST 2015
Hi,
I've created an issue for this so it doesn't get completely lost:
https://bugs.gnupg.org/gnupg/issue1990
Thanks,
Neal
At Mon, 3 Nov 2014 11:05:03 +0000,
Dimitri John Ledkov wrote:
>
> Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov at intel.com>
> ---
> gtk+-2/gtksecentry.c | 84 ++++++++++++++++++++++++++++++-------------------
> gtk+-2/pinentry-gtk-2.c | 22 ++++++++-----
> 2 files changed, 66 insertions(+), 40 deletions(-)
>
> diff --git a/gtk+-2/gtksecentry.c b/gtk+-2/gtksecentry.c
> index 824d45a..1b630ac 100644
> --- a/gtk+-2/gtksecentry.c
> +++ b/gtk+-2/gtksecentry.c
> @@ -802,7 +802,7 @@ gtk_secure_entry_get_property(GObject * object,
> static void
> gtk_secure_entry_init(GtkSecureEntry * entry)
> {
> - GTK_WIDGET_SET_FLAGS(entry, GTK_CAN_FOCUS);
> + gtk_widget_set_can_focus((GtkWidget *)entry, TRUE);
>
> entry->text_size = MIN_SIZE;
> WITH_SECURE_MEM(entry->text = g_malloc(entry->text_size));
> @@ -864,7 +864,7 @@ gtk_secure_entry_realize(GtkWidget * widget)
> GdkWindowAttr attributes;
> gint attributes_mask;
>
> - GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
> + gtk_widget_set_realized(widget, TRUE);
> entry = GTK_SECURE_ENTRY(widget);
>
> attributes.window_type = GDK_WINDOW_CHILD;
> @@ -888,9 +888,9 @@ gtk_secure_entry_realize(GtkWidget * widget)
> attributes_mask =
> GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
>
> - widget->window =
> + gtk_widget_set_window (widget,
> gdk_window_new(gtk_widget_get_parent_window(widget), &attributes,
> - attributes_mask);
> + attributes_mask));
> gdk_window_set_user_data(widget->window, entry);
>
> get_text_area_size(entry, &attributes.x, &attributes.y,
> @@ -911,10 +911,10 @@ gtk_secure_entry_realize(GtkWidget * widget)
>
> gdk_window_set_background(widget->window,
> &widget->style->
> - base[GTK_WIDGET_STATE(widget)]);
> + base[gtk_widget_get_state(widget)]);
> gdk_window_set_background(entry->text_area,
> &widget->style->
> - base[GTK_WIDGET_STATE(widget)]);
> + base[gtk_widget_get_state(widget)]);
>
> gdk_window_show(entry->text_area);
>
> @@ -1074,7 +1074,7 @@ gtk_secure_entry_size_allocate(GtkWidget * widget,
>
> widget->allocation = *allocation;
>
> - if (GTK_WIDGET_REALIZED(widget)) {
> + if (gtk_widget_get_realized(widget)) {
> /* We call gtk_widget_get_child_requisition, since we want (for
> * backwards compatibility reasons) the realization here to
> * be affected by the usize of the entry, if set
> @@ -1105,9 +1105,14 @@ gtk_secure_entry_draw_frame(GtkWidget * widget)
> "interior-focus", &interior_focus,
> "focus-line-width", &focus_width, NULL);
>
> +#if GTK_CHECK_VERSION (2, 24, 0)
> + width = gdk_window_get_width(widget->window);
> + height = gdk_window_get_height(widget->window);
> +#else
> gdk_drawable_get_size(widget->window, &width, &height);
> +#endif
>
> - if (GTK_WIDGET_HAS_FOCUS(widget) && !interior_focus) {
> + if (gtk_widget_has_focus(widget) && !interior_focus) {
> x += focus_width;
> y += focus_width;
> width -= 2 * focus_width;
> @@ -1118,14 +1123,14 @@ gtk_secure_entry_draw_frame(GtkWidget * widget)
> GTK_STATE_NORMAL, GTK_SHADOW_IN,
> NULL, widget, "entry", x, y, width, height);
>
> - if (GTK_WIDGET_HAS_FOCUS(widget) && !interior_focus) {
> + if (gtk_widget_has_focus(widget) && !interior_focus) {
> x -= focus_width;
> y -= focus_width;
> width += 2 * focus_width;
> height += 2 * focus_width;
>
> gtk_paint_focus(widget->style, widget->window,
> - GTK_WIDGET_STATE(widget), NULL, widget, "entry", 0,
> + gtk_widget_get_state(widget), NULL, widget, "entry", 0,
> 0, width, height);
> }
> }
> @@ -1143,12 +1148,12 @@ gtk_secure_entry_expose(GtkWidget * widget, GdkEventExpose * event)
> get_text_area_size(entry, NULL, NULL, &area_width, &area_height);
>
> gtk_paint_flat_box(widget->style, entry->text_area,
> - GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE,
> + gtk_widget_get_state(widget), GTK_SHADOW_NONE,
> NULL, widget, "entry_bg",
> 0, 0, area_width, area_height);
>
> if ((entry->invisible_char != 0) &&
> - GTK_WIDGET_HAS_FOCUS(widget) &&
> + gtk_widget_has_focus(widget) &&
> entry->selection_bound == entry->current_pos
> && entry->cursor_visible)
> gtk_secure_entry_draw_cursor(GTK_SECURE_ENTRY(widget));
> @@ -1171,7 +1176,7 @@ gtk_secure_entry_button_press(GtkWidget * widget, GdkEventButton * event)
>
> entry->button = event->button;
>
> - if (!GTK_WIDGET_HAS_FOCUS(widget)) {
> + if (!gtk_widget_has_focus(widget)) {
> entry->in_click = TRUE;
> gtk_widget_grab_focus(widget);
> entry->in_click = FALSE;
> @@ -1248,7 +1253,11 @@ gtk_secure_entry_motion_notify(GtkWidget * widget, GdkEventMotion * event)
>
> {
> gint height;
> +#if GTK_CHECK_VERSION (2, 24, 0)
> + height = gdk_window_get_height(entry->text_area);
> +#else
> gdk_drawable_get_size(entry->text_area, NULL, &height);
> +#endif
>
> if (event->y < 0)
> tmp_pos = 0;
> @@ -1385,7 +1394,7 @@ gtk_secure_entry_grab_focus(GtkWidget * widget)
> GtkSecureEntry *entry = GTK_SECURE_ENTRY(widget);
> gboolean select_on_focus;
>
> - GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_DEFAULT);
> + gtk_widget_set_can_default(widget, TRUE);
> GTK_WIDGET_CLASS(parent_class)->grab_focus(widget);
>
> /* read current select on focus setting from GtkEntry */
> @@ -1416,16 +1425,16 @@ gtk_secure_entry_state_changed(GtkWidget * widget,
> {
> GtkSecureEntry *entry = GTK_SECURE_ENTRY(widget);
>
> - if (GTK_WIDGET_REALIZED(widget)) {
> + if (gtk_widget_get_realized(widget)) {
> gdk_window_set_background(widget->window,
> &widget->style->
> - base[GTK_WIDGET_STATE(widget)]);
> + base[gtk_widget_get_state(widget)]);
> gdk_window_set_background(entry->text_area,
> &widget->style->
> - base[GTK_WIDGET_STATE(widget)]);
> + base[gtk_widget_get_state(widget)]);
> }
>
> - if (!GTK_WIDGET_IS_SENSITIVE(widget)) {
> + if (!gtk_widget_is_sensitive(widget)) {
> /* Clear any selection */
> gtk_editable_select_region(GTK_EDITABLE(entry), entry->current_pos,
> entry->current_pos);
> @@ -1553,13 +1562,13 @@ gtk_secure_entry_style_set(GtkWidget * widget, GtkStyle * previous_style)
>
> gtk_secure_entry_recompute(entry);
>
> - if (previous_style && GTK_WIDGET_REALIZED(widget)) {
> + if (previous_style && gtk_widget_get_realized(widget)) {
> gdk_window_set_background(widget->window,
> &widget->style->
> - base[GTK_WIDGET_STATE(widget)]);
> + base[gtk_widget_get_state(widget)]);
> gdk_window_set_background(entry->text_area,
> &widget->style->
> - base[GTK_WIDGET_STATE(widget)]);
> + base[gtk_widget_get_state(widget)]);
> }
> }
>
> @@ -2026,7 +2035,7 @@ gtk_secure_entry_real_activate(GtkSecureEntry * entry)
> widget != window->default_widget &&
> !(widget == window->focus_widget &&
> (!window->default_widget
> - || !GTK_WIDGET_SENSITIVE(window->default_widget))))
> + || !gtk_widget_get_sensitive(window->default_widget))))
> gtk_window_activate_default(window);
> }
> }
> @@ -2300,7 +2309,7 @@ gtk_secure_entry_create_layout(GtkSecureEntry * entry,
>
> pango_dir = pango_find_base_dir(entry->text, entry->n_bytes);
> if (pango_dir == PANGO_DIRECTION_NEUTRAL) {
> - if (GTK_WIDGET_HAS_FOCUS(widget)) {
> + if (gtk_widget_has_focus(widget)) {
> GdkDisplay *display = gtk_widget_get_display(widget);
> GdkKeymap *keymap = gdk_keymap_get_for_display(display);
> pango_dir = gdk_keymap_get_direction(keymap);
> @@ -2411,7 +2420,7 @@ gtk_secure_entry_draw_text(GtkSecureEntry * entry)
> if (entry->invisible_char == 0)
> return;
>
> - if (GTK_WIDGET_DRAWABLE(entry)) {
> + if (gtk_widget_is_drawable((GtkWidget *)entry)) {
> PangoLayout *layout = gtk_secure_entry_ensure_layout(entry, TRUE);
> gint x, y;
> gint start_pos, end_pos;
> @@ -2445,7 +2454,7 @@ gtk_secure_entry_draw_text(GtkSecureEntry * entry)
>
> pango_layout_get_extents(layout, NULL, &logical_rect);
>
> - if (GTK_WIDGET_HAS_FOCUS(entry)) {
> + if (gtk_widget_has_focus((GtkWidget *)entry)) {
> selection_gc = widget->style->base_gc[GTK_STATE_SELECTED];
> text_gc = widget->style->text_gc[GTK_STATE_SELECTED];
> } else {
> @@ -2508,7 +2517,7 @@ gtk_secure_entry_draw_cursor(GtkSecureEntry * entry)
> (GTK_WIDGET(entry)));
> PangoDirection keymap_direction = gdk_keymap_get_direction(keymap);
>
> - if (GTK_WIDGET_DRAWABLE(entry)) {
> + if (gtk_widget_is_drawable((GtkWidget *)entry)) {
> GtkWidget *widget = GTK_WIDGET(entry);
> GdkRectangle cursor_location;
> gboolean split_cursor;
> @@ -2521,7 +2530,12 @@ gtk_secure_entry_draw_cursor(GtkSecureEntry * entry)
> gint x1 = 0;
> gint x2 = 0;
>
> +
> +#if GTK_CHECK_VERSION (2, 24, 0)
> + text_area_height = gdk_window_get_height(entry->text_area);
> +#else
> gdk_drawable_get_size(entry->text_area, NULL, &text_area_height);
> +#endif
>
> gtk_secure_entry_get_cursor_locations(entry, &strong_x, &weak_x);
>
> @@ -2567,7 +2581,7 @@ gtk_secure_entry_draw_cursor(GtkSecureEntry * entry)
> static void
> gtk_secure_entry_queue_draw(GtkSecureEntry * entry)
> {
> - if (GTK_WIDGET_REALIZED(entry))
> + if (gtk_widget_get_realized((GtkWidget *)entry))
> gdk_window_invalidate_rect(entry->text_area, NULL, FALSE);
> }
>
> @@ -2656,10 +2670,14 @@ gtk_secure_entry_adjust_scroll(GtkSecureEntry * entry)
> PangoLayoutLine *line;
> PangoRectangle logical_rect;
>
> - if (!GTK_WIDGET_REALIZED(entry))
> + if (!gtk_widget_get_realized((GtkWidget *)entry))
> return;
>
> +#if GTK_CHECK_VERSION (2, 24, 0)
> + text_area_width = gdk_window_get_width(entry->text_area);
> +#else
> gdk_drawable_get_size(entry->text_area, &text_area_width, NULL);
> +#endif
> text_area_width -= 2 * INNER_BORDER;
>
> layout = gtk_secure_entry_ensure_layout(entry, TRUE);
> @@ -3309,7 +3327,7 @@ cursor_blinks(GtkSecureEntry * entry)
> GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(entry));
> gboolean blink;
>
> - if (GTK_WIDGET_HAS_FOCUS(entry) &&
> + if (gtk_widget_has_focus((GtkWidget *)entry) &&
> entry->selection_bound == entry->current_pos) {
> g_object_get(settings, "gtk-cursor-blink", &blink, NULL);
> return blink;
> @@ -3334,7 +3352,7 @@ show_cursor(GtkSecureEntry * entry)
> if (!entry->cursor_visible) {
> entry->cursor_visible = TRUE;
>
> - if (GTK_WIDGET_HAS_FOCUS(entry)
> + if (gtk_widget_has_focus((GtkWidget *)entry)
> && entry->selection_bound == entry->current_pos)
> gtk_widget_queue_draw(GTK_WIDGET(entry));
> }
> @@ -3346,7 +3364,7 @@ hide_cursor(GtkSecureEntry * entry)
> if (entry->cursor_visible) {
> entry->cursor_visible = FALSE;
>
> - if (GTK_WIDGET_HAS_FOCUS(entry)
> + if (gtk_widget_has_focus((GtkWidget *)entry)
> && entry->selection_bound == entry->current_pos)
> gtk_widget_queue_draw(GTK_WIDGET(entry));
> }
> @@ -3364,14 +3382,14 @@ blink_cb(gpointer data)
>
> entry = GTK_SECURE_ENTRY(data);
>
> - if (!GTK_WIDGET_HAS_FOCUS(entry)) {
> + if (!gtk_widget_has_focus((GtkWidget *)entry)) {
> g_warning
> ("GtkSecureEntry - did not receive focus-out-event. If you\n"
> "connect a handler to this signal, it must return\n"
> "FALSE so the entry gets the event as well");
> }
>
> - g_assert(GTK_WIDGET_HAS_FOCUS(entry));
> + g_assert(gtk_widget_has_focus((GtkWidget *)entry));
> g_assert(entry->selection_bound == entry->current_pos);
>
> if (entry->cursor_visible) {
> diff --git a/gtk+-2/pinentry-gtk-2.c b/gtk+-2/pinentry-gtk-2.c
> index 1a8c083..235bd99 100644
> --- a/gtk+-2/pinentry-gtk-2.c
> +++ b/gtk+-2/pinentry-gtk-2.c
> @@ -65,7 +65,9 @@ static GtkWidget *qualitybar;
> static GtkWidget *insure;
> static GtkWidget *time_out;
> #endif
> +#if !GTK_CHECK_VERSION (2, 12, 0)
> static GtkTooltips *tooltips;
> +#endif
> static gboolean got_input;
>
> /* Gnome hig small and large space in pixels. */
> @@ -127,7 +129,7 @@ make_transient (GtkWidget *win, GdkEvent *event, gpointer data)
> /* Make window transient for the root window. */
> screen = gdk_screen_get_default ();
> root = gdk_screen_get_root_window (screen);
> - gdk_window_set_transient_for (win->window, root);
> + gdk_window_set_transient_for (gtk_widget_get_window(win), root);
> }
>
>
> @@ -138,7 +140,7 @@ grab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data)
> if (! pinentry->grab)
> return FALSE;
>
> - if (gdk_keyboard_grab (win->window, FALSE, gdk_event_get_time (event)))
> + if (gdk_keyboard_grab (gtk_widget_get_window(win), FALSE, gdk_event_get_time (event)))
> {
> g_critical ("could not grab keyboard");
> grab_failed = 1;
> @@ -157,7 +159,7 @@ ungrab_keyboard (GtkWidget *win, GdkEvent *event, gpointer data)
> /* gdk_window_set_transient_for cannot be used with parent = NULL to
> unset transient hint (unlike gtk_ version which can). Replacement
> code is taken from gtk_window_transient_parent_unrealized. */
> - gdk_property_delete (win->window,
> + gdk_property_delete (gtk_widget_get_window(win),
> gdk_atom_intern_static_string ("WM_TRANSIENT_FOR"));
> return FALSE;
> }
> @@ -330,7 +332,9 @@ create_window (int confirm_mode)
> GtkAccelGroup *acc;
> gchar *msg;
>
> +#if !GTK_CHECK_VERSION (2, 12, 0)
> tooltips = gtk_tooltips_new ();
> +#endif
>
> /* FIXME: check the grabbing code against the one we used with the
> old gpg-agent */
> @@ -471,8 +475,12 @@ create_window (int confirm_mode)
> QUALITYBAR_EMPTY_TEXT);
> gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (qualitybar), 0.0);
> if (pinentry->quality_bar_tt)
> +#if !GTK_CHECK_VERSION (2, 12, 0)
> gtk_tooltips_set_tip (GTK_TOOLTIPS (tooltips), qualitybar,
> pinentry->quality_bar_tt, "");
> +#else
> + gtk_widget_set_tooltip_text (qualitybar, pinentry->quality_bar_tt);
> +#endif
> gtk_table_attach (GTK_TABLE (table), qualitybar, 1, 2, nrow, nrow+1,
> GTK_EXPAND|GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
> nrow++;
> @@ -561,7 +569,7 @@ create_window (int confirm_mode)
> G_CALLBACK (confirm_mode ? confirm_button_clicked
> : button_clicked),
> (gpointer) CONFIRM_CANCEL);
> - GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
> + gtk_widget_set_can_default (w, TRUE);
> }
>
> if (confirm_mode && !pinentry->one_button && pinentry->notok)
> @@ -574,7 +582,7 @@ create_window (int confirm_mode)
> g_signal_connect (G_OBJECT (w), "clicked",
> G_CALLBACK (confirm_button_clicked),
> (gpointer) CONFIRM_NOTOK);
> - GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
> + gtk_widget_set_can_default (w, TRUE);
> }
>
> if (pinentry->ok)
> @@ -602,7 +610,7 @@ create_window (int confirm_mode)
> {
> g_signal_connect (G_OBJECT (w), "clicked",
> G_CALLBACK (button_clicked), "ok");
> - GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
> + gtk_widget_set_can_default (w, TRUE);
> gtk_widget_grab_default (w);
> g_signal_connect_object (G_OBJECT (entry), "focus_in_event",
> G_CALLBACK (gtk_widget_grab_default),
> @@ -613,7 +621,7 @@ create_window (int confirm_mode)
> g_signal_connect (G_OBJECT (w), "clicked",
> G_CALLBACK(confirm_button_clicked),
> (gpointer) CONFIRM_OK);
> - GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
> + gtk_widget_set_can_default (w, TRUE);
> }
>
> gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
> --
> 2.1.0
>
>
> _______________________________________________
> Gnupg-devel mailing list
> Gnupg-devel at gnupg.org
> http://lists.gnupg.org/mailman/listinfo/gnupg-devel
>
More information about the Gnupg-devel
mailing list