Blob


1 /*
2 * Copyright (c) 2020 Omar Polo <op@omarpolo.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #ifndef STAR_PLATINUM_H
18 #define STAR_PLATINUM_H
20 /* XXX: why I need to define this to get XK_space/...?
21 * is this a bad idea? there is another way? */
22 #define XK_LATIN1
23 #define XK_MISCELLANY
25 #include <X11/Xlib.h>
27 #include <err.h>
28 #include <stdlib.h>
30 void yyerror(const char*, ...);
32 struct key {
33 unsigned int modifier;
34 KeySym key;
35 };
37 struct action {
38 #define ASPECIAL 1
39 #define AFAKE 2
40 #define AEXEC 3
41 int type;
42 union {
43 #define ATOGGLE 1
44 #define AACTIVATE 2
45 #define ADEACTIVATE 3
46 #define AIGNORE 4
47 int special;
48 struct key send_key;
49 char *str;
50 };
51 };
53 void do_action(struct action, Window, XKeyEvent*);
54 void free_action(struct action);
56 struct match {
57 #define MANY 1
58 #define MCLASS 2
59 int prop;
60 char *str;
61 struct match *next;
62 };
64 struct match *new_match(int, char*);
65 void recfree_match(struct match*);
66 int match_window(struct match*, Window);
68 struct rule {
69 struct key key;
70 struct action action;
71 struct rule *next;
72 };
74 struct rule *new_rule(struct key, struct action);
75 void recfree_rule(struct rule*);
76 int rule_matched(struct rule*, struct key);
78 struct group {
79 struct match *matches;
80 struct rule *rules;
81 struct group *next;
82 };
84 extern struct group *config;
86 struct group *new_group(struct match*, struct rule*);
87 void recfree_group(struct group*);
88 void process_event(struct group*, XKeyEvent*);
89 int group_match(struct group*, Window);
91 /* xlib-related */
92 int error_handler(Display*, XErrorEvent*);
93 void grabkey(struct key, Window);
94 void grab_matching_keys(Window);
95 int grabkey_matching_windows();
96 KeySym keycode_to_keysym(unsigned int);
97 Window focused_window();
98 void send_fake(Window, struct key, XKeyEvent*);
99 int window_match_class(Window, const char*);
101 /* debugging */
102 void printkey(struct key);
103 void printaction(struct action);
104 void printmatch(struct match*);
105 void printrule(struct rule*);
106 void printgroup(struct group*);
108 #endif /* STAR_PLATINUM_H */