Skip to content

Commit

Permalink
Merge pull request #1 from fejfighter/pgtk-menu
Browse files Browse the repository at this point in the history
Implement menubar for pgtk emacs
  • Loading branch information
Yuuki Harano committed Jun 16, 2019
2 parents 465ffa8 + f2aad24 commit 12f863c
Show file tree
Hide file tree
Showing 10 changed files with 576 additions and 85 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -2841,7 +2841,7 @@ LIBS=$OLD_LIBS
PGTK_OBJ=
PGTK_LIBS=
if test "$window_system" = "pgtk"; then
PGTK_OBJ="pgtkfns.o pgtkterm.o pgtkselect.o xsettings.o"
PGTK_OBJ="pgtkfns.o pgtkterm.o pgtkselect.o pgtkmenu.o xsettings.o"
PGTK_LIBS="$GTK_LIBS -ldl"
AC_DEFINE([HAVE_PGTK], 1, [Define to 1 if you have pure Gtk+-3.])
fi
Expand Down
1 change: 1 addition & 0 deletions lisp/menu-bar.el
Expand Up @@ -2343,6 +2343,7 @@ See `menu-bar-mode' for more information."

(declare-function x-menu-bar-open "term/x-win" (&optional frame))
(declare-function w32-menu-bar-open "term/w32-win" (&optional frame))
(declare-function pgtk-menu-bar-open "term/pgtk-win" (&optional frame))

(defun lookup-key-ignore-too-long (map key)
"Call `lookup-key' and convert numeric values to nil."
Expand Down
1 change: 1 addition & 0 deletions src/emacs.c
Expand Up @@ -1836,6 +1836,7 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
syms_of_pgtkterm();
syms_of_pgtkfns();
syms_of_pgtkselect ();
syms_of_pgtkmenu ();
syms_of_fontset ();
syms_of_xsettings ();
syms_of_xwidget ();
Expand Down
4 changes: 2 additions & 2 deletions src/lisp.h
Expand Up @@ -3319,12 +3319,12 @@ struct frame;

/* Define if the windowing system provides a menu bar. */
#if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
|| defined (HAVE_NS) || (defined (USE_GTK) && !defined (HAVE_PGTK))
|| defined (HAVE_NS) || defined (USE_GTK)
#define HAVE_EXT_MENU_BAR true
#endif

/* Define if the windowing system provides a tool-bar. */
#if (defined (USE_GTK) && !defined(HAVE_PGTK)) || defined (HAVE_NS)
#if defined (USE_GTK) || defined (HAVE_NS)
#define HAVE_EXT_TOOL_BAR true
#endif

Expand Down
6 changes: 6 additions & 0 deletions src/menu.h
Expand Up @@ -59,6 +59,12 @@ extern Lisp_Object ns_menu_show (struct frame *, int, int, int,
Lisp_Object, const char **);
extern void ns_activate_menubar (struct frame *);
#endif
#ifdef HAVE_PGTK
extern Lisp_Object pgtk_menu_show (struct frame *, int, int, int,
Lisp_Object, const char **);
extern void pgtk_activate_menubar (struct frame *);
#endif

extern Lisp_Object tty_menu_show (struct frame *, int, int, int,
Lisp_Object, const char **);
extern ptrdiff_t menu_item_width (const unsigned char *);
Expand Down
117 changes: 44 additions & 73 deletions src/pgtkfns.c
Expand Up @@ -468,102 +468,84 @@ pgtk_set_doc_edited (void)
static void
x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
{
#if 0
int nlines;
if (FRAME_MINIBUF_ONLY_P (f))
/* Right now, menu bars don't work properly in minibuf-only frames;
most of the commands try to apply themselves to the minibuffer
frame itself, and get an error because you can't switch buffers
in or split the minibuffer window. */
if (FRAME_MINIBUF_ONLY_P (f) || FRAME_PARENT_FRAME (f))
return;

if (TYPE_RANGED_INTEGERP (int, value))
if (TYPE_RANGED_FIXNUMP (int, value))
nlines = XFIXNUM (value);
else
nlines = 0;

/* Make sure we redisplay all windows in this frame. */
fset_redisplay (f);

FRAME_MENU_BAR_LINES (f) = 0;
FRAME_MENU_BAR_HEIGHT (f) = 0;
if (nlines)
{
FRAME_EXTERNAL_MENU_BAR (f) = 1;
/* does for all frames, whereas we just want for one frame
[NSMenu setMenuBarVisible: YES]; */
if (FRAME_PGTK_P (f) && f->output_data.pgtk->menubar_widget == 0)
/* Make sure next redisplay shows the menu bar. */
XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = true;
}
else
{
if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
free_frame_menubar (f);
/* [NSMenu setMenuBarVisible: NO]; */
free_frame_menubar (f);
FRAME_EXTERNAL_MENU_BAR (f) = 0;
if (FRAME_X_P (f))
f->output_data.pgtk->menubar_widget = 0;
}

adjust_frame_glyphs (f);
}

/* Set the pixel height of the tool bar of frame F to HEIGHT. */
void
x_change_tool_bar_height (struct frame *f, int height)
{
FRAME_TOOL_BAR_LINES (f) = 0;
FRAME_TOOL_BAR_HEIGHT (f) = 0;
if (height)
{
FRAME_EXTERNAL_TOOL_BAR (f) = true;
if (FRAME_X_P (f) && f->output_data.pgtk->toolbar_widget == 0)
/* Make sure next redisplay shows the tool bar. */
XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = true;
update_frame_tool_bar (f);
}
else
{
if (FRAME_EXTERNAL_TOOL_BAR (f))
free_frame_tool_bar (f);
FRAME_EXTERNAL_TOOL_BAR (f) = false;
}
#endif
}


/* toolbar support */
static void
x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
{
#if 0
/* Currently, when the tool bar change state, the frame is resized.
TODO: It would be better if this didn't occur when 1) the frame
is full height or maximized or 2) when specified by
`frame-inhibit-implied-resize'. */
int nlines;

NSTRACE ("x_set_tool_bar_lines");

/* Treat tool bars like menu bars. */
if (FRAME_MINIBUF_ONLY_P (f))
return;

if (RANGED_INTEGERP (0, value, INT_MAX))
/* Use VALUE only if an int >= 0. */
if (RANGED_FIXNUMP (0, value, INT_MAX))
nlines = XFIXNAT (value);
else
nlines = 0;

if (nlines)
{
FRAME_EXTERNAL_TOOL_BAR (f) = 1;
update_frame_tool_bar (f);
}
else
{
if (FRAME_EXTERNAL_TOOL_BAR (f))
{
free_frame_tool_bar (f);
FRAME_EXTERNAL_TOOL_BAR (f) = 0;

{
EmacsView *view = FRAME_PGTK_VIEW (f);
int fs_state = [view fullscreenState];

if (fs_state == FULLSCREEN_MAXIMIZED)
{
[view setFSValue:FULLSCREEN_WIDTH];
}
else if (fs_state == FULLSCREEN_HEIGHT)
{
[view setFSValue:FULLSCREEN_NONE];
}
}
}
}
x_change_tool_bar_height (f, nlines * FRAME_LINE_HEIGHT (f));

{
int inhibit
= ((f->after_make_frame
&& !f->tool_bar_resized
&& (EQ (frame_inhibit_implied_resize, Qt)
|| (CONSP (frame_inhibit_implied_resize)
&& !NILP (Fmemq (Qtool_bar_lines,
frame_inhibit_implied_resize))))
&& NILP (get_frame_param (f, Qfullscreen)))
? 0
: 2);

NSTRACE_MSG ("inhibit:%d", inhibit);

frame_size_history_add (f, Qupdate_frame_tool_bar, 0, 0, Qnil);
adjust_frame_size (f, -1, -1, inhibit, 0, Qtool_bar_lines);
}
#endif
}


Expand Down Expand Up @@ -1459,25 +1441,14 @@ This function is an internal primitive--use `make-frame' instead. */)
gui_default_parameter (f, parms, Qno_accept_focus, Qnil,
NULL, NULL, RES_TYPE_BOOLEAN);

#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
/* Create the menu bar. */
if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
{
#if 0
/* If this signals an error, we haven't set size hints for the
frame and we didn't make it visible. */
initialize_frame_menubar (f);
#endif

#ifndef USE_GTK
/* This is a no-op, except under Motif where it arranges the
main window for the widgets on it. */
lw_set_main_areas (FRAME_X_OUTPUT(f)->column_widget,
FRAME_X_OUTPUT(f)->menubar_widget,
FRAME_X_OUTPUT(f)->edit_widget);
#endif /* not USE_GTK */
}
#endif /* USE_X_TOOLKIT || USE_GTK */

/* Consider frame official, now. */
f->can_set_window_size = true;
Expand Down

0 comments on commit 12f863c

Please sign in to comment.