Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add simple launcher menu entry #1

Merged
merged 1 commit into from
Mar 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cmd/rio/dat.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define CORNER _corner
#define INSET _inset
#define MAXHIDDEN 128
#define B3FIXED 5
#define B3FIXED 6
#define NUMVIRTUALS 12

#define AllButtonMask (Button1Mask|Button2Mask|Button3Mask \
Expand Down Expand Up @@ -140,6 +140,7 @@ extern int nostalgia;
extern char **myargv;
extern Bool shape;
extern char *termprog;
extern char *launcher;
extern char *shell;
extern char *version[];
extern int _border;
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/rio/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ XFontStruct *font;
int nostalgia;
char **myargv;
char *termprog;
char *launcher;
char *shell;
Bool shape;
int _border = 4;
Expand Down Expand Up @@ -108,6 +109,8 @@ main(int argc, char *argv[])
}
else if(strcmp(argv[i], "-term") == 0 && i+1<argc)
termprog = argv[++i];
else if(strcmp(argv[i], "-launcher") == 0 && i+1 < argc)
launcher = argv[++i];
else if(strcmp(argv[i], "-virtuals") == 0 && i+1<argc){
numvirtuals = atoi(argv[++i]);
if(numvirtuals < 0 || numvirtuals > 12){
Expand Down
49 changes: 38 additions & 11 deletions src/cmd/rio/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Menu b2menu =
char *b3items[B3FIXED+MAXHIDDEN+1] =
{
"New",
"Launch",
"Reshape",
"Move",
"Delete",
Expand All @@ -64,6 +65,7 @@ char *b3items[B3FIXED+MAXHIDDEN+1] =
enum
{
New,
Launch,
Reshape,
Move,
Delete,
Expand All @@ -80,6 +82,34 @@ Menu egg =
version
};

void
runterm() {
if(termprog != NULL){
execl(shell, shell, "-c", termprog, (char*)0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the "-c" option specific to some shells ? (I remember it vaguely from bash)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-c is specific to all posix compliant shells...

http://pubs.opengroup.org/onlinepubs/009695399/utilities/sh.html

AFAIK, the shells below have this option:
sh, rc, bash, csh, dash, fish, zsh, nash

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if you recite the sequence of shell names above very fast you get brain damage kkkk

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auheauheauheuaheuhauheuahe

Did not know that, thanks =)

fprintf(stderr, "rio: exec %s", shell);
perror(" failed");
}
execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0);
execlp("xterm", "xterm", "-ut", (char*)0);
perror("rio: exec 9term/xterm failed");
exit(1);
}

void
runlauncher() {
if(launcher != NULL) {
/* launcher parameters uses configured shell syntax */
execl(shell, shell, "-c", launcher, (char*)0);
perror("rio: launcher failed");

/* will try default launcher */
}

execlp("dmenu_run", "dmenu_run", (char*)0);
perror("rio: exec dmenu_run failed");
exit(1);
}

void
button(XButtonEvent *e)
{
Expand Down Expand Up @@ -157,7 +187,10 @@ button(XButtonEvent *e)
cmapnofocus(s);
switch (n = menuhit(e, &b3menu)){
case New:
spawn(s);
spawn(s, runterm);
break;
case Launch:
spawn(s, runlauncher);
break;
case Reshape:
reshape(selectwin(1, 0, s), Button3, sweep, 0);
Expand All @@ -184,7 +217,7 @@ button(XButtonEvent *e)
}

void
spawn(ScreenInfo *s)
spawn(ScreenInfo *s, void (*fn)())
{
/*
* ugly dance to cause sweeping for terminals.
Expand All @@ -205,15 +238,9 @@ spawn(ScreenInfo *s)
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
if(termprog != NULL){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea to extract this logic from here and inject a function =D

execl(shell, shell, "-c", termprog, (char*)0);
fprintf(stderr, "rio: exec %s", shell);
perror(" failed");
}
execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0);
execlp("xterm", "xterm", "-ut", (char*)0);
perror("rio: exec 9term/xterm failed");
exit(1);

// run in child process
fn();
}
exit(0);
}
Expand Down