Skip to content

Commit

Permalink
Cleanup slurp launcher in wlr_screencast.c
Browse files Browse the repository at this point in the history
  • Loading branch information
columbarius committed Oct 8, 2020
1 parent bc95d10 commit e24e913
Showing 1 changed file with 46 additions and 37 deletions.
83 changes: 46 additions & 37 deletions src/screencast/wlr_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,60 +295,70 @@ struct xdpw_wlr_output *xdpw_wlr_output_first(struct wl_list *output_list) {
return NULL;
}

int xdpw_wlr_output_chooser_slurp_launcher(char *name, unsigned long name_maxlength) {
static bool exec_chooser_slurp(char *name, unsigned long name_maxlength) {
int p1[2]; //p -> c
int p2[2]; //c -> p

if (pipe(p1) == -1) {
printf("Failed to open pipe\n");
return -1;
logprint(ERROR,"Failed to open pipe");
return false;
}
if (pipe(p2) == -1) {
printf("Failed to open pipe\n");
return -1;
logprint(ERROR,"Failed to open pipe");
return false;
}

int id = fork();
pid_t pid = fork();

if (id == -1) {
printf("Failed to fork\n");
return 2;
}
if (id == 0) {
if (pid < 0) {
perror("fork");
return false;
} else if (pid == 0) {
close(p1[1]);
close(p2[0]);

dup2(p1[0], STDIN_FILENO);
dup2(p2[1], STDOUT_FILENO);
close(p1[0]);
close(p2[1]);

int err;
char *slurpargs[] = {"slurp" , "-f", "%o", "-o", NULL};
err = execvp(slurpargs[0], slurpargs);
char *const argv[] = {
"slurp",
"-f",
"%o",
"-o",
NULL,
};
err = execvp(argv[0], argv);

if (err == -1) {
printf("Could not find external chooser\n");
return -1;
perror("execvp");
logprint(WARN,"Failed to execute slurp");
return false;
}
abort();
} else {
close(p1[0]);
close(p2[1]);
close(p1[1]);
if (read(p2[0],name,name_maxlength*sizeof(char)) == -1) {
return 3;
}
char *p = strchr(name, '\n');
if (p != NULL) {
*p = '\0';
}
close(p2[0]);
return 0;
exit(127);
}

close(p1[0]);
close(p2[1]);
close(p1[1]);
if (read(p2[0],name,name_maxlength*sizeof(char)) == -1) {
return false;
}

name[name_maxlength -1] = '\0';
char *p = strchr(name, '\n');
if (p != NULL) {
*p = '\0';
}
close(p2[0]);
return true;
}

struct xdpw_wlr_output *xdpw_wlr_output_chooser_slurp(struct wl_list *output_list) {
struct xdpw_wlr_output *wlr_output_chooser_slurp(struct wl_list *output_list) {

logprint(DEBUG, "wlroots: output chooser dmenu called");
logprint(DEBUG, "wlroots: output chooser slurp called");
struct xdpw_wlr_output *output, *tmp;
unsigned long namelength = 0;
int i = 0;
Expand All @@ -361,12 +371,11 @@ struct xdpw_wlr_output *xdpw_wlr_output_chooser_slurp(struct wl_list *output_lis

char name[namelength];

logprint(TRACE, "wlroots: call slurp launcher");
xdpw_wlr_output_chooser_slurp_launcher(name, namelength);

wl_list_for_each_safe(output, tmp, output_list, link) {
if (strcmp(output->name, name) == 0) {
return output;
if (exec_chooser_slurp(name, namelength)) {
wl_list_for_each_safe(output, tmp, output_list, link) {
if (strcmp(output->name, name) == 0) {
return output;
}
}
}
return NULL;
Expand Down

0 comments on commit e24e913

Please sign in to comment.