aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2020-06-21 15:57:51 +0530
committerAkshay Nair <phenax5@gmail.com>2020-06-21 15:57:51 +0530
commit28ec391ae2f5aabd1872df4a783a86de0891951e (patch)
treec0438b0c610903ea606d79e4b80c79198724098d
parentb8c2093f06265840e64c3c15c11723a4278a02cf (diff)
parent900c5a3a955324aad6035c499003b16bbdd0d96c (diff)
downloadshotkey-28ec391ae2f5aabd1872df4a783a86de0891951e.tar.gz
shotkey-28ec391ae2f5aabd1872df4a783a86de0891951e.zip
Merge branch 'master' into personal
-rw-r--r--config.h10
-rw-r--r--shotkey.c34
2 files changed, 23 insertions, 21 deletions
diff --git a/config.h b/config.h
index 19b4110..73827c0 100644
--- a/config.h
+++ b/config.h
@@ -1,7 +1,7 @@
#include <X11/XF86keysym.h>
// Shell
-static char shell[] = "/bin/sh";
+char shell[] = "/bin/sh";
#define Super Mod4Mask
@@ -16,7 +16,7 @@ enum {
// Define mode key bindings here
// NOTE: "10" here is the maximum number of key bindings for each mode
-static Key modes[MODE_SIZE][10] = {
+Key modes[MODE_SIZE][10] = {
[MusicPlayer] = { // {{{
{ 0, XK_l, SCRIPT(spotify.sh next) },
{ 0, XK_h, SCRIPT(spotify.sh prev) },
@@ -25,7 +25,7 @@ static Key modes[MODE_SIZE][10] = {
};
// Define normal mode key bindings here
-static Key keys[] = {
+Key keys[] = {
// Mod Key // Command
// Application {{{
@@ -68,10 +68,10 @@ static Key keys[] = {
// }}}
};
-static ModeProperties mode_properties[MODE_SIZE] = {
+ModeProperties mode_properties[MODE_SIZE] = {
[MusicPlayer] = { "Music player" },
};
// Call this script on mode change
-static char* on_mode_change = "~/scripts/shotkey.sh on-mode-change";
+char* on_mode_change = "~/scripts/shotkey.sh on-mode-change";
diff --git a/shotkey.c b/shotkey.c
index 3df41ce..6c9ed65 100644
--- a/shotkey.c
+++ b/shotkey.c
@@ -3,7 +3,6 @@
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#include <unistd.h>
typedef struct Command {
char* command;
@@ -57,18 +56,21 @@ int error_handler(Display *disp, XErrorEvent *xe) {
}
void spawn(char** command) {
- if (fork() == 0) {
- setsid();
- execve(command[0], command, environ);
- fprintf(stderr, "shotkey: execve %s", command[0]);
- perror(" failed");
- exit(0);
- }
+ if (fork() == 0) {
+ setsid();
+ execve(command[0], command, environ);
+ fprintf(stderr, "shotkey: execve %s", command[0]);
+ perror(" failed");
+ exit(0);
+ }
}
char* get_mode_label() {
- if (current_mode == NormalMode) return "";
- if (LENGTH(mode_properties) <= current_mode) return "";
+ if (current_mode == NormalMode)
+ return "";
+ if (LENGTH(mode_properties) <= current_mode)
+ return "";
+
ModeProperties props = mode_properties[current_mode];
return props.label;
}
@@ -99,7 +101,7 @@ void run(Display* dpy, Window win, Command command) {
if (command.command) {
char* cmd[] = {shell, "-c", command.command, NULL};
spawn(cmd);
- } else if(command.mode != NormalMode) {
+ } else if (command.mode != NormalMode) {
// Bind keyboard for mode
XGrabKeyboard(dpy, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
@@ -171,13 +173,13 @@ int main() {
handle_mode_change();
- /* main event loop */
+ /* main event loop */
XEvent ev;
- XSync(dpy, False);
- while (running) {
+ XSync(dpy, False);
+ while (running) {
XMaskEvent(dpy, KeyPressMask, &ev);
- switch (ev.type) {
+ switch (ev.type) {
case KeyPress: {
keypress(dpy, root, &ev.xkey);
break;
@@ -185,6 +187,6 @@ int main() {
}
}
- XCloseDisplay(dpy);
+ XCloseDisplay(dpy);
}