175 lines
4.4 KiB
C
175 lines
4.4 KiB
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include <X11/Xlib.h>
|
|
#include <X11/Xutil.h>
|
|
#include <X11/Xresource.h>
|
|
#include <X11/Xproto.h>
|
|
#include <X11/Xatom.h>
|
|
#include <X11/extensions/Xinerama.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <signal.h>
|
|
#include <errno.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/un.h>
|
|
|
|
// TODO: when only 1 window on ws it is not focused
|
|
// TODO: dont draw border on not normal windows, floating dialog window,
|
|
// window type/name/... atom member variable on Client struct
|
|
// TODO: get_atom probably not working correctly
|
|
// TODO: important: code cleanliness, ewmh!!
|
|
// TODO: config command line utility(sockets), maybe avoid global vars
|
|
|
|
#define RETURN_IF_NULL(c) \
|
|
if (c == NULL) \
|
|
{ \
|
|
fprintf(stderr, "wm: variable %s was null in function %s\n", #c, __func__); \
|
|
return; \
|
|
}
|
|
|
|
#define DEBUG 1
|
|
|
|
#define DEBUG_PRINT(fmt, ...) \
|
|
do { if (DEBUG) fprintf(stderr, fmt, ##__VA_ARGS__); } while (0);
|
|
|
|
typedef struct Client Client;
|
|
typedef struct Monitor Monitor;
|
|
typedef struct Keybind Keybind;
|
|
typedef struct Arg Arg;
|
|
|
|
enum Direction {
|
|
UP,
|
|
DOWN,
|
|
LEFT,
|
|
RIGHT
|
|
};
|
|
|
|
struct Monitor {
|
|
Display *display;
|
|
XineramaScreenInfo info;
|
|
Client *clients;
|
|
int *wss;
|
|
int selws;
|
|
int wscount;
|
|
};
|
|
|
|
struct Client {
|
|
int x;
|
|
int y;
|
|
int w;
|
|
int h;
|
|
int ws;
|
|
bool hidden;
|
|
Monitor *m;
|
|
Window window;
|
|
Client *prev;
|
|
Client *next;
|
|
char *name;
|
|
bool has_border;
|
|
bool is_floating;
|
|
// linked list is not sufficent for manual tiling.
|
|
// will propably need a tree.
|
|
};
|
|
|
|
struct Arg {
|
|
int i;
|
|
unsigned int ui;
|
|
Client *c;
|
|
char* s;
|
|
char **sl;
|
|
|
|
int count;
|
|
};
|
|
|
|
struct Keybind {
|
|
unsigned int mask;
|
|
KeySym keysym;
|
|
void (*func)(Arg*);
|
|
Arg args;
|
|
};
|
|
|
|
static Display *wm_display;
|
|
static Monitor *wm_monitors;
|
|
static Monitor *wm_smon;
|
|
static int wm_mc;
|
|
static bool wm_other_wm;
|
|
static Client wm_root;
|
|
static Window wm_dock = -1;
|
|
|
|
/* global configuration variables */
|
|
// TODO: active layout not working
|
|
static void (*wm_active_layout)(Monitor*);
|
|
static float wm_cfg_ms_p = 0.5;
|
|
static char wm_cfg_border_col[] = "#222222";
|
|
static char wm_cfg_focused_border_col[] = "#444444";
|
|
static unsigned char wm_cfg_border_width = 2;
|
|
static Keybind *wm_cfg_keybinds;
|
|
static int wm_cfg_kb_count;
|
|
static bool wm_cfg_focus_on_motion = true;
|
|
|
|
static int wm_socket_fd;
|
|
|
|
static int wm_xerror_handler(Display *display, XErrorEvent *e);
|
|
static int wm_other_wm_handler(Display *display, XErrorEvent *e);
|
|
void wm_create_handler(XCreateWindowEvent e);
|
|
void wm_destroy_handler(XDestroyWindowEvent e);
|
|
void wm_reparent_handler(XReparentEvent e);
|
|
void wm_configure_handler(XConfigureRequestEvent e);
|
|
void wm_keyrelease_handler(XKeyReleasedEvent e);
|
|
void wm_keypress_handler(XKeyPressedEvent e);
|
|
void wm_maprequest_handler(XMapRequestEvent e);
|
|
void wm_motion_handler(XMotionEvent e);
|
|
|
|
Monitor wm_monitor_open(Display *d, XineramaScreenInfo info);
|
|
void wm_monitors_open_all(Display *d);
|
|
Display* wm_connect_display();
|
|
|
|
void wm_mstack(Monitor *m);
|
|
void wm_set_layout(void(*f)(Monitor*));
|
|
void wm_layout(Monitor *m);
|
|
|
|
Client *wm_get_last_client(Monitor m);
|
|
|
|
void wm_client_set_atom(Client *c, const char *name, const unsigned char *data,
|
|
Atom type, int nelements);
|
|
Atom wm_client_get_atom(Client *c, const char *name, unsigned char **atom_ret,
|
|
unsigned long *nitems_ret);
|
|
|
|
Client* wm_client_create(Window w);
|
|
void wm_client_free(Client *c);
|
|
void wm_client_kill(Client *c);
|
|
void wm_client_hide(Client *c);
|
|
void wm_client_show(Client *c);
|
|
void wm_client_focus(Client *c);
|
|
void wm_client_focus_dir(Client *c, int dir);
|
|
Client* wm_client_get_dir_rel_c(Client *c, int dir);
|
|
Client* wm_client_get_focused();
|
|
void wm_client_border(Client *c);
|
|
void wm_client_border_focused(Client *c);
|
|
void wm_monitor_clients_border(Monitor *m);
|
|
bool wm_client_is_focused(Client *c);
|
|
bool wm_window_is_dock(Window w);
|
|
XWindowChanges wm_client_to_xwchanges(Client c);
|
|
Client* wm_client_find(Window w);
|
|
|
|
void wm_spawn(char **str);
|
|
|
|
void wm_switch_ws(int ws);
|
|
void wm_mainloop();
|
|
void wm_init();
|
|
|
|
void wm_grab_keys();
|
|
void wm_kb_spawn(Arg *args);
|
|
void wm_kb_kill(Arg *args);
|
|
void wm_kb_switch_ws(Arg *args);
|
|
void wm_kb_focus_dir(Arg *args);
|
|
|
|
void wm_keybinds_init_def();
|
|
|
|
struct sockaddr wm_socket_init();
|
|
void wm_socket_cleanup();
|
|
void wm_settings_message_parse(char *c, int len);
|
|
|
|
void wm_sigint_handler(int signum);
|