Wmfs: Thread WMFS if status.sh is present, So update status.sh by itself each status_timing second, and add wmfs -S to update status.sh. !REPLACE YOUR STATUS.SH! (no loop anymore in the script) Requested by Matrhack.
This commit is contained in:
parent
f62e59117f
commit
796a72ecb8
@ -54,7 +54,7 @@ add_executable(wmfs ${wmfs_src})
|
|||||||
set(VERSION "WMFS-200912")
|
set(VERSION "WMFS-200912")
|
||||||
|
|
||||||
# FLAGS
|
# FLAGS
|
||||||
set(CFLAGS "-g -Wall -ansi")
|
set(CFLAGS "-g -Wall -lpthread -ansi")
|
||||||
set(CMAKE_C_FLAGS ${CFLAGS})
|
set(CMAKE_C_FLAGS ${CFLAGS})
|
||||||
|
|
||||||
# Linker FLAGS
|
# Linker FLAGS
|
||||||
|
|||||||
15
rc/status.sh
15
rc/status.sh
@ -1,20 +1,13 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Print
|
#WMFS status.sh example file
|
||||||
|
#Will be executed if put in ~/.config/wmfs/
|
||||||
TIMING=1
|
#Timing adjustable in wmfsrc (misc -> status_timing)
|
||||||
RET=0
|
|
||||||
|
|
||||||
statustext()
|
statustext()
|
||||||
{
|
{
|
||||||
local DATE=`date`
|
local DATE=`date`
|
||||||
|
|
||||||
wmfs -s "$DATE"
|
wmfs -s "$DATE"
|
||||||
|
|
||||||
RET=$?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while [[ $RET == "0" ]];
|
statustext
|
||||||
do
|
|
||||||
statustext
|
|
||||||
sleep $TIMING
|
|
||||||
done
|
|
||||||
|
|||||||
17
src/config.c
17
src/config.c
@ -136,11 +136,12 @@ conf_misc_section(char *src)
|
|||||||
|
|
||||||
cfg_set_sauv(src);
|
cfg_set_sauv(src);
|
||||||
|
|
||||||
conf.font = get_opt(src, "sans-9", "font").str;
|
conf.font = get_opt(src, "sans-9", "font").str;
|
||||||
conf.raisefocus = get_opt(src, "false", "raisefocus").bool;
|
conf.raisefocus = get_opt(src, "false", "raisefocus").bool;
|
||||||
conf.raiseswitch = get_opt(src, "false", "raiseswitch").bool;
|
conf.raiseswitch = get_opt(src, "false", "raiseswitch").bool;
|
||||||
conf.focus_fmouse = get_opt(src, "true", "focus_follow_mouse").bool;
|
conf.focus_fmouse = get_opt(src, "true", "focus_follow_mouse").bool;
|
||||||
pad = get_opt(src, "12", "pad").num;
|
conf.status_timing = get_opt(src, "1", "status_timing").num;
|
||||||
|
pad = get_opt(src, "12", "pad").num;
|
||||||
|
|
||||||
if(pad > 24 || pad < 1)
|
if(pad > 24 || pad < 1)
|
||||||
{
|
{
|
||||||
@ -151,6 +152,12 @@ conf_misc_section(char *src)
|
|||||||
|
|
||||||
conf.pad = pad;
|
conf.pad = pad;
|
||||||
|
|
||||||
|
if(conf.status_timing <= 0)
|
||||||
|
{
|
||||||
|
warnx("configuration : status_timing value (%d) incorrect.", conf.status_timing);
|
||||||
|
conf.status_timing = 1;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -231,6 +231,10 @@ clientmessageevent(XClientMessageEvent *ev)
|
|||||||
screen_get_sel();
|
screen_get_sel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(mess_t == wmfs_update_status
|
||||||
|
&& estatus)
|
||||||
|
spawn(status_path);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -80,6 +80,7 @@ ewmh_init_hints(void)
|
|||||||
/* WMFS hints */
|
/* WMFS hints */
|
||||||
net_atom[wmfs_running] = ATOM("_WMFS_RUNNING");
|
net_atom[wmfs_running] = ATOM("_WMFS_RUNNING");
|
||||||
net_atom[wmfs_update_hints] = ATOM("_WMFS_UPDATE_HINTS");
|
net_atom[wmfs_update_hints] = ATOM("_WMFS_UPDATE_HINTS");
|
||||||
|
net_atom[wmfs_update_status] = ATOM("_WMFS_UPDATE_STATUS");
|
||||||
net_atom[wmfs_set_screen] = ATOM("_WMFS_SET_SCREEN");
|
net_atom[wmfs_set_screen] = ATOM("_WMFS_SET_SCREEN");
|
||||||
net_atom[wmfs_screen_count] = ATOM("_WMFS_SCREEN_COUNT");
|
net_atom[wmfs_screen_count] = ATOM("_WMFS_SCREEN_COUNT");
|
||||||
net_atom[wmfs_current_tag] = ATOM("_WMFS_CURRENT_TAG");
|
net_atom[wmfs_current_tag] = ATOM("_WMFS_CURRENT_TAG");
|
||||||
|
|||||||
21
src/init.c
21
src/init.c
@ -195,32 +195,33 @@ init_layout(void)
|
|||||||
void
|
void
|
||||||
init_status(void)
|
init_status(void)
|
||||||
{
|
{
|
||||||
char *path;
|
|
||||||
int fd;
|
int fd;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
path = emalloc(strlen(getenv("HOME")) + strlen(DEF_STATUS) + 2, sizeof(char));
|
status_path = emalloc(strlen(getenv("HOME")) + strlen(DEF_STATUS) + 2, sizeof(char));
|
||||||
|
|
||||||
sprintf(path, "%s/"DEF_STATUS, getenv("HOME"));
|
sprintf(status_path, "%s/"DEF_STATUS, getenv("HOME"));
|
||||||
|
|
||||||
if(!(fd = open(path, O_RDONLY)))
|
if(!(fd = open(status_path, O_RDONLY)))
|
||||||
{
|
{
|
||||||
free(path);
|
free(status_path);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stat(path, &st);
|
stat(status_path, &st);
|
||||||
|
|
||||||
if(st.st_mode & S_IXUSR)
|
if(st.st_mode & S_IXUSR)
|
||||||
spawn(path);
|
{
|
||||||
|
estatus = True;
|
||||||
|
system(status_path);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
warnx("status.sh file present in wmfs directory can't be executed, try 'chmod +x %s'.", path);
|
warnx("status.sh file present in wmfs directory can't be executed, try 'chmod +x %s'.",
|
||||||
|
status_path);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
free(path);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -120,6 +120,7 @@ enum
|
|||||||
/* WMFS HINTS */
|
/* WMFS HINTS */
|
||||||
wmfs_running,
|
wmfs_running,
|
||||||
wmfs_update_hints,
|
wmfs_update_hints,
|
||||||
|
wmfs_update_status,
|
||||||
wmfs_current_tag,
|
wmfs_current_tag,
|
||||||
wmfs_current_screen,
|
wmfs_current_screen,
|
||||||
wmfs_current_layout,
|
wmfs_current_layout,
|
||||||
@ -321,6 +322,7 @@ typedef struct
|
|||||||
Bool raiseswitch;
|
Bool raiseswitch;
|
||||||
Bool focus_fmouse;
|
Bool focus_fmouse;
|
||||||
uint pad;
|
uint pad;
|
||||||
|
int status_timing;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
|||||||
72
src/wmfs.c
72
src/wmfs.c
@ -136,15 +136,53 @@ quit(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
thread_process(void *arg)
|
||||||
|
{
|
||||||
|
XEvent ev;
|
||||||
|
|
||||||
|
/* X event loop */
|
||||||
|
if(!(int*)arg)
|
||||||
|
{
|
||||||
|
while(!exiting && !XNextEvent(dpy, &ev))
|
||||||
|
getevent(ev);
|
||||||
|
|
||||||
|
pthread_exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Status checking loop with timing */
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while(!exiting)
|
||||||
|
{
|
||||||
|
spawn(status_path);
|
||||||
|
sleep(conf.status_timing);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** WMFS main loop.
|
/** WMFS main loop.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
mainloop(void)
|
mainloop(void)
|
||||||
{
|
{
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
|
pthread_t evloop, evstatus;
|
||||||
|
void *ret;
|
||||||
|
|
||||||
while(!exiting && !XNextEvent(dpy, &ev))
|
if(!estatus)
|
||||||
getevent(ev);
|
while(!exiting && !XNextEvent(dpy, &ev))
|
||||||
|
getevent(ev);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pthread_create(&evloop, NULL, thread_process, "1");
|
||||||
|
pthread_create(&evstatus, NULL, thread_process, NULL);
|
||||||
|
|
||||||
|
(void)pthread_join(evloop, &ret);
|
||||||
|
(void)pthread_join(evstatus, &ret);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -347,6 +385,23 @@ set_statustext(int s, char *str)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Update status script by ewmh hint
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
update_status(void)
|
||||||
|
{
|
||||||
|
long data[5];
|
||||||
|
|
||||||
|
if(!check_wmfs_running())
|
||||||
|
return;
|
||||||
|
|
||||||
|
data[4] = True;
|
||||||
|
|
||||||
|
send_client_event(data, "_WMFS_UPDATE_STATUS");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/** Signal handle function
|
/** Signal handle function
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
@ -368,12 +423,12 @@ int
|
|||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *ol = "csgV";
|
char *ol = "csgVS";
|
||||||
|
|
||||||
argv_global = _strdup(argv[0]);
|
argv_global = _strdup(argv[0]);
|
||||||
sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME"));
|
sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME"));
|
||||||
|
|
||||||
while((i = getopt(argc, argv, "hvic:s:g:C:V:")) != -1)
|
while((i = getopt(argc, argv, "hviSc:s:g:C:V:")) != -1)
|
||||||
{
|
{
|
||||||
|
|
||||||
/* For options who need WMFS running */
|
/* For options who need WMFS running */
|
||||||
@ -384,12 +439,13 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
printf("usage: %s [-ihv] [-C <file>] [-c <uicb function> <cmd> ] [-g <argument>] [-s <screen_num> <string>] [-V <viwmfs cmd]\n"
|
printf("usage: %s [-ihvS] [-C <file>] [-c <uicb function> <cmd> ] [-g <argument>] [-s <screen_num> <string>] [-V <viwmfs cmd]\n"
|
||||||
" -C <file> Load a configuration file\n"
|
" -C <file> Load a configuration file\n"
|
||||||
" -c <uicb_function> <cmd> Execute an uicb function to control WMFS\n"
|
" -c <uicb_function> <cmd> Execute an uicb function to control WMFS\n"
|
||||||
" -g <argument> Show information about wmfs status\n"
|
" -g <argument> Show information about wmfs status\n"
|
||||||
" -s <screen_num> <string> Set the bar(s) statustext\n"
|
" -s <screen_num> <string> Set the bar(s) statustext\n"
|
||||||
" -V <viwmfs cmd> Manage WMFS with vi-like command\n"
|
" -V <viwmfs cmd> Manage WMFS with vi-like command\n"
|
||||||
|
" -S Update status script\n"
|
||||||
" -h Show this page\n"
|
" -h Show this page\n"
|
||||||
" -i Show informations\n"
|
" -i Show informations\n"
|
||||||
" -v Show WMFS version\n", argv[0]);
|
" -v Show WMFS version\n", argv[0]);
|
||||||
@ -410,6 +466,12 @@ main(int argc, char **argv)
|
|||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'S':
|
||||||
|
update_status();
|
||||||
|
XCloseDisplay(dpy);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
strcpy(conf.confpath, optarg);
|
strcpy(conf.confpath, optarg);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -44,6 +44,7 @@
|
|||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -334,11 +335,13 @@ void viwmfs(int argc, char **argv);
|
|||||||
int errorhandler(Display *d, XErrorEvent *event);
|
int errorhandler(Display *d, XErrorEvent *event);
|
||||||
int errorhandlerdummy(Display *d, XErrorEvent *event);
|
int errorhandlerdummy(Display *d, XErrorEvent *event);
|
||||||
void quit(void);
|
void quit(void);
|
||||||
|
void *thread_process(void *arg);
|
||||||
void mainloop(void);
|
void mainloop(void);
|
||||||
void scan(void);
|
void scan(void);
|
||||||
Bool check_wmfs_running(void);
|
Bool check_wmfs_running(void);
|
||||||
void exec_uicb_function(char *func, char *cmd);
|
void exec_uicb_function(char *func, char *cmd);
|
||||||
void set_statustext(int s, char *str);
|
void set_statustext(int s, char *str);
|
||||||
|
void update_status(void);
|
||||||
void handle_signal(int signum);
|
void handle_signal(int signum);
|
||||||
void uicb_quit(uicb_t);
|
void uicb_quit(uicb_t);
|
||||||
void uicb_reload(uicb_t);
|
void uicb_reload(uicb_t);
|
||||||
@ -351,12 +354,13 @@ GC gc, gc_stipple;
|
|||||||
int selscreen;
|
int selscreen;
|
||||||
Conf conf;
|
Conf conf;
|
||||||
Key *keys;
|
Key *keys;
|
||||||
Bool exiting;
|
Bool exiting, estatus;
|
||||||
XRectangle *sgeo;
|
XRectangle *sgeo;
|
||||||
XRectangle *spgeo;
|
XRectangle *spgeo;
|
||||||
Cursor cursor[CurLast];
|
Cursor cursor[CurLast];
|
||||||
char *argv_global;
|
char *argv_global, *status_path;
|
||||||
int xrandr_event;
|
int xrandr_event;
|
||||||
|
uint timing;
|
||||||
|
|
||||||
/* Fonts */
|
/* Fonts */
|
||||||
XftFont *font;
|
XftFont *font;
|
||||||
|
|||||||
7
wmfs.1
7
wmfs.1
@ -13,7 +13,7 @@
|
|||||||
.SH "NAME"
|
.SH "NAME"
|
||||||
wmfs \- Window Manager From Scratch
|
wmfs \- Window Manager From Scratch
|
||||||
.SH "SYNOPSIS"
|
.SH "SYNOPSIS"
|
||||||
\fBwmfs\fR [\fB\-ihv\fR] [\fB\-C <file>\fR] [\fB\-c <uicb_function> <cmd>\fR] [\fB\-g <argument>\fR] [\fB\-s <screen_num> <string>\fR] [\fB\-V <viwmfs cmd>\fR]
|
\fBwmfs\fR [\fB\-ihvS\fR] [\fB\-C <file>\fR] [\fB\-c <uicb_function> <cmd>\fR] [\fB\-g <argument>\fR] [\fB\-s <screen_num> <string>\fR] [\fB\-V <viwmfs cmd>\fR]
|
||||||
.sp
|
.sp
|
||||||
.SH "DESCRIPTION"
|
.SH "DESCRIPTION"
|
||||||
\fBWMFS\fR is a basic, lightweight and dynamic tiling windows manager for X\&.
|
\fBWMFS\fR is a basic, lightweight and dynamic tiling windows manager for X\&.
|
||||||
@ -45,6 +45,11 @@ Set the bar(s) statustext. If the screen number is not specified, the string wil
|
|||||||
Manage WMFS with vi-like command\&.
|
Manage WMFS with vi-like command\&.
|
||||||
.RE
|
.RE
|
||||||
.PP
|
.PP
|
||||||
|
\fB\-S\fR
|
||||||
|
.RS 4
|
||||||
|
Update status script\&.
|
||||||
|
.RE
|
||||||
|
.PP
|
||||||
\fB\-v\fR
|
\fB\-v\fR
|
||||||
.RS 4
|
.RS 4
|
||||||
Print version information to standard output, then exit\&.
|
Print version information to standard output, then exit\&.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user