Skip to content

Commit

Permalink
add -p
Browse files Browse the repository at this point in the history
  • Loading branch information
phillbush committed Feb 4, 2021
1 parent afdf94a commit 6a416d8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
11 changes: 11 additions & 0 deletions pmenu.1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pmenu \- pie menu utility for X
.SH SYNOPSIS
.B pmenu
.RB [ \-p ]
.RB [ \-r
.IR button ]
.SH DESCRIPTION
Expand All @@ -15,6 +16,16 @@ The pie menu contains one slice for each item.
.PP
The options are as follows:
.TP
.B \-p
When
.B \-r
is used, pass the click to the root window,
for the window manager to use it, for example.
This may open the window manager's menu (if it has one).
This option only makes sense when
.B \-r
is used.
.TP
.BI "\-r " buton
When this option is used,
.B pmenu
Expand Down
39 changes: 29 additions & 10 deletions pmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static struct Pie pie;

/* flags */
static int rflag = 0; /* whether to run in root mode */
static int pflag = 0; /* whether to pass click to root window */
static unsigned int button; /* button to trigger pmenu in root mode */

#include "config.h"
Expand All @@ -41,7 +42,7 @@ static unsigned int button; /* button to trigger pmenu in root mode */
static void
usage(void)
{
(void)fprintf(stderr, "usage: pmenu [-r button]\n");
(void)fprintf(stderr, "usage: pmenu [-p] [-r button]\n");
exit(1);
}

Expand Down Expand Up @@ -82,17 +83,32 @@ getoptions(int *argc, char ***argv)
{
int ch;

while ((ch = getopt(*argc, *argv, "r:")) != -1) {
while ((ch = getopt(*argc, *argv, "pr:")) != -1) {
switch (ch) {
case 'p':
pflag = 1;
break;
case 'r':
rflag = 1;
switch (*optarg) {
case '1': button = Button1;
case '2': button = Button2;
case '3': button = Button3;
case '4': button = Button4;
case '5': button = Button5;
default: button = Button3;
case '1':
button = Button1;
break;
case '2':
button = Button2;
break;
case '3':
button = Button3;
break;
case '4':
button = Button4;
break;
case '5':
button = Button5;
break;
default:
button = Button3;
break;
}
break;
default:
Expand Down Expand Up @@ -1075,6 +1091,8 @@ run(struct Menu *rootmenu)
while (!XNextEvent(dpy, &ev)) {
if (rflag && !mapped && ev.type == ButtonPress) {
if (ev.xbutton.subwindow == None) {
if (pflag)
XAllowEvents(dpy, ReplayPointer, CurrentTime);
mapped = 1;
getmonitor();
prevmenu = NULL;
Expand All @@ -1084,11 +1102,12 @@ run(struct Menu *rootmenu)
placemenu(currmenu);
prevmenu = mapmenu(currmenu, prevmenu);
XWarpPointer(dpy, None, currmenu->win, 0, 0, 0, 0, pie.radius, pie.radius);
} else {
XAllowEvents(dpy, ReplayPointer, CurrentTime);
}
XAllowEvents(dpy, ReplayPointer, CurrentTime);
continue;
}
switch(ev.type) {
switch (ev.type) {
case Expose:
if (ev.xexpose.count == 0)
copymenu(currmenu);
Expand Down

0 comments on commit 6a416d8

Please sign in to comment.