Skip to content

Commit

Permalink
Menu: add option to grey entries out
Browse files Browse the repository at this point in the history
This adds a "Greyed" option to the menu syntax to explicitly have
entries in a menu which are present but not selectable.  This can
sometimes be useful to indicate options yet to be implemented.

For example:

	AddToMenu Foo
	+ I Greyed "Hello" Exec exec xterm
  • Loading branch information
ThomasAdam committed Jun 25, 2021
1 parent 30166b5 commit 796057c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
5 changes: 4 additions & 1 deletion doc/fvwm3/fvwm3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2128,6 +2128,9 @@ fail and may screw up your menus. See the *Silent* command.
*Warning* Do not issue *MenuStyle* commands as dynamic menu actions.
Chances are good that this crashes fvwm.
+
The keyword _Greyed_ will still render the menu item, but will grey it out
making the option unselectable.
+
There are several configurable scripts installed together with fvwm
for automatic menu generation. They have their own man pages. Some of
them, specifically *fvwm-menu-directory* and *fvwm-menu-desktop*, may
Expand Down Expand Up @@ -4125,7 +4128,7 @@ the move. Moving a window to the edge of the screen can be used to drag the
window to other pages, see *EdgeScroll*, and the *EdgeMoveDelay* style
for more information.
+
The interactive move operation can be aborted with Escape
The interactive move operation can be aborted with Escape
or any mouse button not set to place the window. By default mouse
button 2 is set to cancel the move operation. To change this you may
use the *Mouse* command with special context 'P' for Placement.
Expand Down
7 changes: 4 additions & 3 deletions fvwm/menuitem.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,13 @@ void menuitem_paint(

off_cs = ST_HAS_MENU_CSET(ms) ? ST_CSET_MENU(ms) : -1;
/* Note: it's ok to pass a NULL label to is_function_allowed. */
if (
!IS_EWMH_DESKTOP_FW(mpip->fw) &&
if (MI_SHOULD_BE_GREYED(mi) ||
(!IS_EWMH_DESKTOP_FW(mpip->fw) &&
!is_function_allowed(
MI_FUNC_TYPE(mi), MI_LABEL(mi)[0], mpip->fw,
RQORIG_PROGRAM_US, False))
RQORIG_PROGRAM_US, False)))
{
MI_IS_SELECTABLE(mi) = False;
gcs = ST_MENU_STIPPLE_GCS(ms);
off_gcs = gcs;
off_cs = ST_HAS_GREYED_CSET(ms) ? ST_CSET_GREYED(ms) : -1;
Expand Down
2 changes: 2 additions & 0 deletions fvwm/menuitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define MI_HAS_HOTKEY(i) ((i)->flags.has_hotkey)
#define MI_IS_HOTKEY_AUTOMATIC(i) ((i)->flags.is_hotkey_automatic)
#define MI_IS_SELECTABLE(i) ((i)->flags.is_selectable)
#define MI_SHOULD_BE_GREYED(i) ((i)->flags.must_grey)
/* temporary flags */
#define MI_WAS_DESELECTED(i) ((i)->flags.was_deselected)

Expand Down Expand Up @@ -92,6 +93,7 @@ typedef struct MenuItem
unsigned has_hotkey : 1;
unsigned is_hotkey_automatic : 1;
unsigned is_selectable : 1;
unsigned must_grey : 1;
/* temporary flags */
unsigned was_deselected : 1;
} flags;
Expand Down
13 changes: 13 additions & 0 deletions fvwm/menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -6606,6 +6606,7 @@ void AddToMenu(
int i;
int is_empty;
Bool do_replace_title;
Bool greyed = False;

if (MR_MAPPED_COPIES(mr) > 0)
{
Expand Down Expand Up @@ -6674,6 +6675,14 @@ void AddToMenu(
}
return;
}
else if (StrEquals(item, "Greyed"))
{
greyed = True;
free(item);

GetNextToken(action, &item);
action = "Nop";
}

/*
* Parse the action
Expand Down Expand Up @@ -6800,6 +6809,10 @@ void AddToMenu(
* Set the type flags
*/

if (greyed)
{
MI_SHOULD_BE_GREYED(tmp) = True;
}
if (is_continuation_item)
{
MI_IS_CONTINUATION(tmp) = True;
Expand Down

0 comments on commit 796057c

Please sign in to comment.