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 /xmousepos.c | |
parent | 03030de14057620c73cbad8f9f6b2267ee26d100 (diff) | |
download | xutils-master.tar.gz xutils-master.zip |
Diffstat (limited to 'xmousepos.c')
-rw-r--r-- | xmousepos.c | 62 |
1 files changed, 62 insertions, 0 deletions
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; +} |