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:
committed by
Carlos R. Mafra
parent
38d160cb8c
commit
e16c6fbf2a
@@ -32,7 +32,6 @@
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
|
||||
@@ -62,7 +61,6 @@
|
||||
#include "workspace.h"
|
||||
#include "properties.h"
|
||||
#include "misc.h"
|
||||
#include "event.h"
|
||||
#include "winmenu.h"
|
||||
|
||||
#define MAX_SHORTCUT_LENGTH 32
|
||||
@@ -2971,20 +2969,6 @@ static int setFrameSelectedBorderColor(WScreen * scr, WDefaultEntry * entry, voi
|
||||
return REFRESH_FRAME_BORDER;
|
||||
}
|
||||
|
||||
static void trackDeadProcess(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;
|
||||
}
|
||||
|
||||
static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *tdata, void *bar)
|
||||
{
|
||||
WMPropList *value = tdata;
|
||||
@@ -3005,62 +2989,15 @@ static int setWorkspaceSpecificBack(WScreen * scr, WDefaultEntry * entry, void *
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
pid_t pid;
|
||||
int filedes[2];
|
||||
|
||||
if (WMGetPropListItemCount(value) == 0)
|
||||
return 0;
|
||||
|
||||
if (pipe(filedes) < 0) {
|
||||
werror("pipe() failed:can't set workspace specific background image");
|
||||
|
||||
if (!start_bg_helper(scr)) {
|
||||
WMReleasePropList(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
} 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, trackDeadProcess, scr);
|
||||
|
||||
SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
|
||||
}
|
||||
|
||||
SendHelperMessage(scr, 'P', -1, wPreferences.pixmap_path);
|
||||
}
|
||||
|
||||
for (i = 0; i < WMGetPropListItemCount(value); i++) {
|
||||
|
||||
72
src/misc.c
72
src/misc.c
@@ -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;
|
||||
|
||||
@@ -33,6 +33,9 @@ void move_window(Window win, int from_x, int from_y, int to_x, int to_y);
|
||||
void SlideWindow(Window win, int from_x, int from_y, int to_x, int to_y);
|
||||
void SlideWindows(Window *wins[], int n, int from_x, int from_y, int to_x, int to_y);
|
||||
void ParseWindowName(WMPropList *value, char **winstance, char **wclass, const char *where);
|
||||
|
||||
/* Helper is a 'wmsetbg' subprocess with sets the background for the current workspace */
|
||||
Bool start_bg_helper(WScreen *scr);
|
||||
void SendHelperMessage(WScreen *scr, char type, int workspace, const char *msg);
|
||||
|
||||
char *ShrinkString(WMFont *font, const char *string, int width);
|
||||
|
||||
Reference in New Issue
Block a user