diff options
author | Po Lu <luangruo@yahoo.com> | 2022-02-21 14:29:58 +0800 |
---|---|---|
committer | Po Lu <luangruo@yahoo.com> | 2022-02-21 14:29:58 +0800 |
commit | e087c89b1e243bbd941a4a50b4bf99613e13d016 (patch) | |
tree | 76e292eb90aeb4b5cce459604e595e82ff7c6c93 /src/gtkutil.c | |
parent | 816cf19a3a4a2697392d58516c73374d7aaa1533 (diff) | |
download | emacs-e087c89b1e243bbd941a4a50b4bf99613e13d016.tar.gz emacs-e087c89b1e243bbd941a4a50b4bf99613e13d016.tar.bz2 emacs-e087c89b1e243bbd941a4a50b4bf99613e13d016.zip |
Prevent GTK from setting unreasonable size hints with large menu bars
* src/gtkutil.c (struct _EmacsMenuBar): New struct.
(emacs_menu_bar_init):
(emacs_menu_bar_class_init):
(emacs_menu_bar_get_preferred_width):
(emacs_menu_bar_new): New functions.
(xg_update_menu_item): Use our own menu bar class on GTK 3.
* src/gtkutil.h (EmacsMenuBar): New class.
Diffstat (limited to 'src/gtkutil.c')
-rw-r--r-- | src/gtkutil.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c index 158c29272f5..72eb7ef2bb1 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -76,6 +76,17 @@ typedef struct pgtk_output xp_output; #define XG_TEXT_OPEN GTK_STOCK_OPEN #endif +#ifdef HAVE_GTK3 +static void emacs_menu_bar_get_preferred_width (GtkWidget *, gint *, gint *); + +struct _EmacsMenuBar +{ + GtkMenuBar parent; +}; + +G_DEFINE_TYPE (EmacsMenuBar, emacs_menu_bar, GTK_TYPE_MENU_BAR) +#endif + #ifndef HAVE_PGTK static void xg_im_context_commit (GtkIMContext *, gchar *, gpointer); static void xg_im_context_preedit_changed (GtkIMContext *, gpointer); @@ -128,6 +139,45 @@ bool xg_gtk_initialized; /* Used to make sure xwidget calls are possible static GtkWidget * xg_get_widget_from_map (ptrdiff_t idx); + +#ifdef HAVE_GTK3 +static void +emacs_menu_bar_init (EmacsMenuBar *menu_bar) +{ + return; +} + +static void +emacs_menu_bar_class_init (EmacsMenuBarClass *klass) +{ + GtkWidgetClass *widget_class; + + widget_class = GTK_WIDGET_CLASS (klass); + widget_class->get_preferred_width = emacs_menu_bar_get_preferred_width; +} + +static void +emacs_menu_bar_get_preferred_width (GtkWidget *widget, + gint *minimum, gint *natural) +{ + GtkWidgetClass *widget_class; + + widget_class = GTK_WIDGET_CLASS (emacs_menu_bar_parent_class); + widget_class->get_preferred_width (widget, minimum, natural); + + if (minimum) + *minimum = 0; +} + +static GtkWidget * +emacs_menu_bar_new (void) +{ + return GTK_WIDGET (g_object_new (emacs_menu_bar_get_type (), NULL)); +} + +#endif + + /*********************************************************************** Display handling functions ***********************************************************************/ @@ -3287,7 +3337,12 @@ create_menus (widget_value *data, } else { +#ifndef HAVE_GTK3 wmenu = gtk_menu_bar_new (); +#else + wmenu = emacs_menu_bar_new (); +#endif + #ifdef HAVE_PGTK g_signal_connect (G_OBJECT (wmenu), "button-press-event", G_CALLBACK (menu_bar_button_pressed_cb), f); |