1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 20:38:08 +01:00

wmaker: moved the code for the bg helper to a dedicated function

In order to make code easier to maintain, the code related to creating the
Helper process (which helps by setting the background of the workspace) is
moved to a dedicated function, which have been moved to the same location
as the function for communicating with the helper.

Took opportunity to de-CamelCase the related names.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
Signed-off-by: Carlos R. Mafra <crmafra@gmail.com>
This commit is contained in:
Christophe CURIS
2014-11-15 19:40:41 +01:00
committed by Carlos R. Mafra
parent 38d160cb8c
commit e16c6fbf2a
3 changed files with 77 additions and 65 deletions

View File

@@ -28,6 +28,7 @@
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
#include <pwd.h>
#include <math.h>
@@ -49,6 +50,8 @@
#include "dialog.h"
#include "xutil.h"
#include "xmodifier.h"
#include "main.h"
#include "event.h"
#define ICON_SIZE wPreferences.icon_size
@@ -906,6 +909,75 @@ static void UnescapeWM_CLASS(const char *str, char **name, char **class)
}
}
static void track_bg_helper_death(pid_t pid, unsigned int status, void *client_data)
{
WScreen *scr = (WScreen *) client_data;
/* Parameter not used, but tell the compiler that it is ok */
(void) pid;
(void) status;
close(scr->helper_fd);
scr->helper_fd = 0;
scr->helper_pid = 0;
scr->flags.backimage_helper_launched = 0;
}
Bool start_bg_helper(WScreen *scr)
{
pid_t pid;
int filedes[2];
if (pipe(filedes) < 0) {
werror("pipe() failed:can't set workspace specific background image");
return False;
}
pid = fork();
if (pid < 0) {
werror("fork() failed:can't set workspace specific background image");
if (close(filedes[0]) < 0)
werror("could not close pipe");
if (close(filedes[1]) < 0)
werror("could not close pipe");
return False;
} else if (pid == 0) {
char *dither;
SetupEnvironment(scr);
if (close(0) < 0)
werror("could not close pipe");
if (dup(filedes[0]) < 0) {
werror("dup() failed:can't set workspace specific background image");
}
dither = wPreferences.no_dithering ? "-m" : "-d";
if (wPreferences.smooth_workspace_back)
execlp("wmsetbg", "wmsetbg", "-helper", "-S", dither, NULL);
else
execlp("wmsetbg", "wmsetbg", "-helper", dither, NULL);
werror("could not execute wmsetbg");
exit(1);
} else {
if (fcntl(filedes[0], F_SETFD, FD_CLOEXEC) < 0) {
werror("error setting close-on-exec flag");
}
if (fcntl(filedes[1], F_SETFD, FD_CLOEXEC) < 0) {
werror("error setting close-on-exec flag");
}
scr->helper_fd = filedes[1];
scr->helper_pid = pid;
scr->flags.backimage_helper_launched = 1;
wAddDeathHandler(pid, track_bg_helper_death, scr);
return True;
}
}
void SendHelperMessage(WScreen *scr, char type, int workspace, const char *msg)
{
char *buffer;