aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/i3_tmux_vim_focus.c
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/i3_tmux_vim_focus.c')
-rwxr-xr-x.local/bin/i3_tmux_vim_focus.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/.local/bin/i3_tmux_vim_focus.c b/.local/bin/i3_tmux_vim_focus.c
new file mode 100755
index 0000000..1429e3a
--- /dev/null
+++ b/.local/bin/i3_tmux_vim_focus.c
@@ -0,0 +1,78 @@
+/* File: i3_vim_focus.c
+ *
+ * Compile with:
+ * gcc i3_tmux_vim_focus.c -lX11 -lxdo -o i3_tmux_vim_focus $(pkg-config --libs --cflags i3ipc-glib-1.0)
+ *
+ */
+
+#include <stdio.h>
+
+#include <strings.h>
+#include <string.h>
+
+#include <xdo.h>
+
+#include <glib/gprintf.h>
+#include <i3ipc-glib/i3ipc-glib.h>
+
+int main(int argc, char *argv[]) {
+
+ char cmd[20];
+
+ unsigned char *name;
+ int name_len;
+ int name_type;
+ Window window_ret;
+
+ i3ipcConnection *conn;
+ gchar *reply;
+
+ if(argc < 2){
+ printf("Missing argument\n");
+ return 1;
+ }
+
+ xdo_t *xdo = xdo_new(NULL);
+ xdo_get_active_window(xdo, &window_ret);
+ xdo_get_window_name(xdo, window_ret, &name, &name_len, &name_type);
+
+ puts(name);
+ if(strstr(name, "VIM") || strstr(name, "vim") && !strstr(name, "i3_tmux_vim_focus"))
+ {
+ strcpy(cmd, "Ctrl+c+Ctrl+");
+
+
+ strcat(cmd, (argv[1][0] == 'l')? "h" :
+ (argv[1][0] == 'd')? "j" :
+ (argv[1][0] == 'u')? "k" :
+ "l" );
+ puts(cmd);
+
+ xdo_send_keysequence_window(xdo, window_ret, cmd, 0);
+ }
+ else if(strstr(name, "tmux"))
+ {
+ strcpy(cmd, "ctrl+a");
+
+
+ xdo_send_keysequence_window(xdo, window_ret, cmd, 0);
+ strcpy(cmd, (argv[1][0] == 'l')? "Left" :
+ (argv[1][0] == 'd')? "Down" :
+ (argv[1][0] == 'u')? "Up" :
+ "Right" );
+
+ xdo_send_keysequence_window(xdo, window_ret, cmd, 0);
+ }
+ else
+ {
+ conn = i3ipc_connection_new(NULL, NULL);
+ strcpy(cmd, "focus ");
+ strcat(cmd, argv[1]);
+ reply = i3ipc_connection_message(conn, I3IPC_MESSAGE_TYPE_COMMAND, cmd, NULL);
+ g_free(reply);
+ g_object_unref(conn);
+ }
+
+ XFree(name);
+ return 0;
+}