-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxdo.c
96 lines (76 loc) · 2.27 KB
/
xdo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright (C) 2018, Jason Parker
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "include/lamprey.h"
#include "include/xdo.h"
void *hl_xdo_init() {
struct hl_xdo *hl_xdo = malloc(sizeof(struct hl_xdo));
printf("libxdo module version: %s\n", xdo_version());
hl_xdo->xdo = xdo_new(NULL);
return hl_xdo;
}
void hl_xdo_dostuff(struct hl_xdo *hl_xdo) {
Window activewindow = 0;
Window *searchwindow = NULL;
unsigned int nwindows;
char *test_window_name = "LiveSplit";
hl_xdo_getactive(hl_xdo->xdo, &activewindow);
printf("Active Window: %ld\n", activewindow);
hl_xdo_search(hl_xdo->xdo, test_window_name, &searchwindow, &nwindows);
if (nwindows > 0) {
printf("%s Window: %ld\n", test_window_name, searchwindow[0]);
if (!hl_xdo_activate(hl_xdo->xdo, searchwindow[0])) {
hl_xdo_keys(hl_xdo->xdo, searchwindow[0], "1");
}
}
hl_xdo_activate(hl_xdo->xdo, activewindow);
}
int hl_xdo_getactive(xdo_t *xdo, Window *window_ret) {
int ret = xdo_get_active_window(xdo, window_ret);
return ret;
}
int hl_xdo_search(xdo_t *xdo, char *window_name, Window **window_ret, unsigned int *nwindows) {
int ret;
xdo_search_t search;
memset(&search, 0, sizeof(xdo_search_t));
search.max_depth = -1;
search.require = SEARCH_ALL;
search.searchmask |= SEARCH_NAME;
search.searchmask |= SEARCH_ONLYVISIBLE;
search.limit = 1;
search.winname = window_name;
ret = xdo_search_windows(xdo, &search, window_ret, nwindows);
return ret;
}
int hl_xdo_activate(xdo_t *xdo, Window window) {
int ret = xdo_activate_window(xdo, window);
if (ret) {
return ret;
} else {
int r;
Window activewindow = 0;
while (activewindow != window) {
r = xdo_get_active_window(xdo, &activewindow);
if (r == XDO_ERROR) {
return r;
}
usleep(1000);
}
// xdo_wait_for_window_active(xdo, window, 1);
}
return ret;
}
int hl_xdo_keys(xdo_t *xdo, Window window, const char *keyseq) {
useconds_t key_delay = 50000;
int ret = xdo_send_keysequence_window(xdo, window, keyseq, key_delay);
return ret;
}