1#ifndef GLITCH_H
  2#define GLITCH_H
  3
  4#include <stdio.h>
  5#include <unistd.h>
  6
  7#include <X11/Xlib.h>
  8#include <X11/keysym.h>
  9#include <X11/XF86keysym.h>
 10#include <X11/Xft/Xft.h>
 11#include <pulse/pulseaudio.h>
 12
 13#ifndef MAX
 14#define MAX(a, b) ((a) > (b) ? (a) : (b))
 15#endif
 16#define LENGTH(x) (sizeof(x) / sizeof((x)[0]))
 17
 18#define NUM_DESKTOPS 9
 19
 20extern Atom _NET_WM_DESKTOP;
 21
 22#define COLOR_INFO     "\x1B[0m"   // White
 23#define COLOR_DEBUG    "\x1B[36m"  // Cyan
 24#define COLOR_WARNING  "\x1B[33m"  // Yellow
 25#define COLOR_ERROR    "\x1B[31m"  // Red
 26#define COLOR_RESET    "\x1B[0m"
 27
 28typedef enum {
 29	LOG_ERROR,
 30	LOG_WARNING,
 31	LOG_INFO,
 32	LOG_DEBUG,
 33} LogLevel;
 34
 35typedef enum {
 36	LAYOUT_FLOATING,
 37	LAYOUT_TILING,
 38} LayoutMode;
 39
 40typedef struct {
 41	unsigned long normal_active;
 42	unsigned long normal_inactive;
 43	unsigned long sticky_active;
 44	unsigned long sticky_inactive;
 45	unsigned long on_top_active;
 46	unsigned long on_top_inactive;
 47} Borders;
 48
 49typedef struct Client {
 50	Window window;
 51	struct Client *next;
 52	struct Client *prev;
 53	int saved_x, saved_y;
 54	unsigned int saved_w, saved_h;
 55	int has_saved_state;
 56} Client;
 57
 58typedef struct {
 59	char *name;
 60	char *exec;
 61	int usage;
 62} LauncherItem;
 63
 64typedef struct {
 65	Display *dpy;
 66	Window root;
 67	Window active;
 68	int screen;
 69	XEvent ev;
 70	XButtonEvent start;
 71	XWindowAttributes attr;
 72
 73	Cursor cursor_default;
 74	Cursor cursor_move;
 75	Cursor cursor_resize;
 76
 77	Colormap cmap;
 78	Borders borders;
 79
 80	int running;
 81	int restart;
 82
 83	unsigned int current_desktop;
 84	XftFont *font;
 85	XftFont *launcher_font;
 86	XftDraw *xft_draw;
 87	XftColor xft_color;
 88	XftColor xft_bg_color;
 89	XftColor xft_root_bg_color;
 90	XftColor xft_widget_color;
 91	XftColor xft_mic_active_bg;
 92	XftColor xft_mic_muted_bg;
 93	XftColor xft_mic_active_fg;
 94	XftColor xft_mic_muted_fg;
 95	XftColor xft_layout_tile_bg;
 96	XftColor xft_layout_float_bg;
 97	XftColor xft_layout_tile_fg;
 98	XftColor xft_layout_float_fg;
 99
100	XftColor xft_launcher_bg;
101	XftColor xft_launcher_border;
102	XftColor xft_launcher_fg;
103	XftColor xft_launcher_hl_bg;
104	XftColor xft_launcher_hl_fg;
105
106	unsigned long last_widget_update;
107	Client *clients;
108
109	int is_cycling;
110	Window cycle_win;
111	Window *cycle_clients;
112	int cycle_count;
113	int active_cycle_index;
114
115	// Layout management
116	LayoutMode layout_modes[NUM_DESKTOPS + 1]; // 1-indexed for convenience
117
118	// PulseAudio
119	pa_threaded_mainloop *pa_mainloop;
120	pa_context *pa_ctx;
121	int mic_muted;
122
123	// Launcher
124	int launcher_active;
125	Window launcher_win;
126	LauncherItem *launcher_items;
127	int launcher_items_count;
128	LauncherItem **launcher_filtered;
129	int launcher_filtered_count;
130	char launcher_search[256];
131	int launcher_selected;
132} WindowManager;
133
134typedef struct {
135	int i;
136	const char *s;
137} Arg;
138
139typedef struct {
140	unsigned int mod;
141	KeySym keysym;
142	void (*func)(const Arg *);
143	Arg arg;
144} Keybinds;
145
146typedef struct {
147	unsigned int mod;
148	KeySym keysym;
149	const char *cmd;
150} Shortcut;
151
152void set_log_level(LogLevel level);
153LogLevel get_log_level_from_env(void);
154void log_message(FILE *stream, LogLevel level, const char* format, ...);
155
156void init_window_manager(void);
157void deinit_window_manager(void);
158void handle_map_request(void);
159void handle_map_notify(void);
160void handle_unmap_notify(void);
161void handle_destroy_notify(void);
162void handle_property_notify(void);
163void handle_motion_notify(void);
164void handle_client_message(void);
165void handle_button_press(void);
166void handle_button_release(void);
167void handle_key_press(void);
168void handle_key_release(void);
169void handle_focus_in(void);
170void handle_focus_out(void);
171void handle_enter_notify(void);
172void handle_expose(void);
173void handle_configure_request(void);
174void handle_configure_notify(void);
175
176Window get_active_window(void);
177void set_active_window(Window window, Time time);
178void set_active_border(Window window);
179void grab_buttons(Window window);
180void get_cursor_offset(Window window, int *dx, int *dy);
181int window_exists(Window window);
182int ignore_x_error(Display *dpy, XErrorEvent *err);
183
184void move_window_x(const Arg *arg);
185void move_window_y(const Arg *arg);
186void resize_window_x(const Arg *arg);
187void resize_window_y(const Arg *arg);
188void window_snap_up(const Arg *arg);
189void window_snap_down(const Arg *arg);
190void window_snap_left(const Arg *arg);
191void window_snap_right(const Arg *arg);
192void window_hmaximize(const Arg *arg);
193void window_vmaximize(const Arg *arg);
194void close_window(const Arg *arg);
195
196void quit(const Arg *arg);
197void reload(const Arg *arg);
198
199void goto_desktop(const Arg *arg);
200void send_window_to_desktop(const Arg *arg);
201void toggle_pip(const Arg *arg);
202int is_sticky(Window window);
203int is_always_on_top(Window window);
204void update_client_list(void);
205void toggle_always_on_top(const Arg *arg);
206void execute_shortcut(const char *command);
207void cycle_active_window(const Arg *arg);
208void end_cycling(void);
209void toggle_fullscreen(const Arg *arg);
210void center_window(const Arg *arg);
211
212void widget_desktop_indicator(void);
213void widget_datetime(void);
214void widget_mic_indicator(void);
215void widget_layout_indicator(void);
216void redraw_widgets(void);
217
218void init_audio(void);
219void deinit_audio(void);
220void toggle_mic_mute(const Arg *arg);
221
222void apply_tiling_layout(void);
223void toggle_layout(const Arg *arg);
224
225void toggle_launcher(const Arg *arg);
226void launcher_handle_key(void);
227void launcher_draw(void);
228
229#endif // GLITCH_H