emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master e087c89b1e: Prevent GTK from setting unreasonable size hints with


From: Po Lu
Subject: master e087c89b1e: Prevent GTK from setting unreasonable size hints with large menu bars
Date: Mon, 21 Feb 2022 01:31:10 -0500 (EST)

branch: master
commit e087c89b1e243bbd941a4a50b4bf99613e13d016
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    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.
---
 src/gtkutil.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gtkutil.h |  4 ++++
 2 files changed, 59 insertions(+)

diff --git a/src/gtkutil.c b/src/gtkutil.c
index 158c29272f..72eb7ef2bb 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);
diff --git a/src/gtkutil.h b/src/gtkutil.h
index b74244d84d..f850ecc421 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -83,6 +83,10 @@ typedef struct xg_menu_item_cb_data_
 
 } xg_menu_item_cb_data;
 
+#ifdef HAVE_GTK3
+G_DECLARE_FINAL_TYPE (EmacsMenuBar, emacs_menu_bar, EMACS, MENU_BAR, 
GtkMenuBar)
+#endif
+
 extern bool xg_uses_old_file_dialog (void);
 
 extern char *xg_get_file_name (struct frame *f,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]