diff options
-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; +} |