summaryrefslogtreecommitdiff
path: root/xmousepos.c
diff options
context:
space:
mode:
authorDaniel Jones <admin@danieljon.es>2019-09-17 16:00:32 +0930
committerDaniel Jones <admin@danieljon.es>2019-09-17 16:17:06 +0930
commitd3c9a4f3f1bf75d87f2c27daf84ca54eaad1f280 (patch)
treeb6791c61f213cca61118c0501a571a2aca60afb3 /xmousepos.c
parent03030de14057620c73cbad8f9f6b2267ee26d100 (diff)
downloadxutils-master.tar.gz
xutils-master.zip
build xbell with c89, make code c89 compliant. also add unfinished xmousepos projectHEADmaster
Diffstat (limited to 'xmousepos.c')
-rw-r--r--xmousepos.c62
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;
+}