diff options
author | Daniel Jones <admin@danieljon.es> | 2019-09-17 16:00:32 +0930 |
---|---|---|
committer | Daniel Jones <admin@danieljon.es> | 2019-09-17 16:17:06 +0930 |
commit | d3c9a4f3f1bf75d87f2c27daf84ca54eaad1f280 (patch) | |
tree | b6791c61f213cca61118c0501a571a2aca60afb3 | |
parent | 03030de14057620c73cbad8f9f6b2267ee26d100 (diff) | |
download | xutils-d3c9a4f3f1bf75d87f2c27daf84ca54eaad1f280.tar.gz xutils-d3c9a4f3f1bf75d87f2c27daf84ca54eaad1f280.zip |
-rw-r--r-- | makefile | 8 | ||||
-rw-r--r-- | xbell.c | 18 | ||||
-rw-r--r-- | xmousepos.c | 62 |
3 files changed, 77 insertions, 11 deletions
@@ -1,11 +1,13 @@ -all: binstatus xwake xbell +all: binstatus xwake xbell xmousepos binstatus: binstatus.c cc -o binstatus binstatus.c -lX11 xwake: xwake.c cc -o xwake xwake.c -lX11 -lXss xbell: xbell.c - cc -o xbell xbell.c -lX11 + cc -g -Wall -std=c89 -pedantic -o xbell xbell.c -lX11 +xmousepos: xmousepos.c + cc -g -Wall -std=c89 -pedantic -o xmousepos xmousepos.c -lX11 clean: - @rm -f binstatus xwake xbell + @rm -f binstatus xwake xbell xmousepos @rm -f *.o @@ -47,7 +47,11 @@ forkexecute() pid_t pid = fork(); if (pid == 0) { - // child process, we don't want to ignore signals + char *args[ARG_LIMIT]; + char *buff = malloc(BUFF_SIZE); + char *t; + int z; + /* child process, we don't want to ignore signals */ signal(SIGCHLD, SIG_DFL); /* * we don't want std{out,err} to be associated with the terminal, @@ -56,8 +60,6 @@ forkexecute() */ freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr); - char *args[ARG_LIMIT]; - char *buff = malloc(BUFF_SIZE); if (buff == NULL) { perror("malloc"); @@ -69,9 +71,9 @@ forkexecute() * that we will use in execvp */ strncpy(buff, program, BUFF_SIZE-1); - char *t = strtok(buff, " "); - int z = 0; - while (t != NULL && z < ARG_LIMIT-1) // save a position for NULL + t = strtok(buff, " "); + z = 0; + while (t != NULL && z < ARG_LIMIT-1) /* save a position for NULL */ { args[z] = t; t = strtok(NULL, " "); @@ -103,9 +105,9 @@ bellevent(void) int main(void) { - // ignore child processes + /* ignore child processes */ signal(SIGCHLD, SIG_IGN); - // ignore return values for now + /* ignore return values for now */ display = XkbOpenDisplay(NULL, &xkbeventcode, NULL, NULL, NULL, NULL); if (!display) { diff --git a/xmousepos.c b/xmousepos.c new file mode 100644 index 0000000..11525bf --- /dev/null +++ b/xmousepos.c @@ -0,0 +1,62 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <pwd.h> +#include <X11/Xlib.h> + +#define BUFFSIZE 256 +#define XPOSITIONFILE "/.xmousepos" + +char * +gethomepath(char *dest, size_t size) +{ + /* + * copy home path into dest with maximum length size + * get home path from $HOME first, if that is fails + * use the user database + */ + char *home; + home = getenv("HOME"); + if (home) + strncpy(dest, home, size); + if (home == NULL || dest == NULL) /* last ditch attempt */ + { + uid_t uid; + struct passwd *pw; + uid = getuid(); + pw = getpwuid(uid); + if (pw == NULL) + return NULL; + strncpy(dest, pw->pw_dir, size); + } + return dest; +} + +int +main(int argc, char *argv[]) +{ + char *path; + Display *display; + /* attempt to get path before anything */ + path = malloc(BUFFSIZE); + gethomepath(path, BUFFSIZE); + if (path == NULL) + { + goto freeandexit; + } + strncat(path, XPOSITIONFILE, BUFFSIZE); + puts(path); + + /* open display */ + display = XOpenDisplay(NULL); + if (display == NULL) + fprintf(stderr, "cannot open x display\n"); + + + +freeandexit: + XCloseDisplay(display); + free(path); + return 0; +} |