169 lines
3.8 KiB
C
169 lines
3.8 KiB
C
/*
|
|
The GPLv3 License (GPLv3)
|
|
|
|
Copyright (c) 2022 Akos Horvath
|
|
|
|
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.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef WM_H
|
|
#define WM_H
|
|
|
|
#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;
|
|
typedef struct Wm Wm;
|
|
|
|
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)(Wm*, Arg*);
|
|
Arg args;
|
|
};
|
|
|
|
struct Wm {
|
|
// TODO INIT
|
|
Display *display;
|
|
Monitor *monitors;
|
|
Monitor *smon;
|
|
int wm_mc;
|
|
bool other_wm;
|
|
Client root;
|
|
Window dock;
|
|
|
|
// TODO: active layout not working
|
|
void (*active_layout)(Wm *wm, Monitor*);
|
|
float cfg_ms_p;
|
|
char *cfg_border_col;
|
|
char *cfg_focused_border_col;
|
|
unsigned char cfg_border_width;
|
|
Keybind *cfg_keybinds;
|
|
int cfg_kb_count;
|
|
bool cfg_focus_on_motion;
|
|
|
|
int socket_fd;
|
|
};
|
|
|
|
Monitor wm_monitor_open(Display *d, XineramaScreenInfo info);
|
|
void wm_monitors_open_all(Wm *wm, Display *d);
|
|
Display* wm_connect_display();
|
|
|
|
void wm_mstack(Wm *wm, Monitor *m);
|
|
void wm_set_layout(Wm *wm, void(*f)(Wm *wm, Monitor*));
|
|
void wm_layout(Wm *wm, Monitor *m);
|
|
bool wm_window_is_dock(Wm* wm, Window w);
|
|
|
|
void wm_spawn(Wm* wm, char **str);
|
|
|
|
void wm_switch_ws(Wm* wm, int ws);
|
|
void wm_mainloop(Wm* wm);
|
|
void wm_init(Wm *wm);
|
|
void wm_init_cfg_def(Wm *wm);
|
|
|
|
void wm_grab_keys(Wm *wm);
|
|
void wm_kb_spawn(Wm *wm, Arg *args);
|
|
void wm_kb_kill(Wm *wm, Arg *args);
|
|
void wm_kb_switch_ws(Wm *wm, Arg *args);
|
|
void wm_kb_focus_dir(Wm *wm, Arg *args);
|
|
|
|
void wm_keybinds_init_def(Wm *wm);
|
|
|
|
struct sockaddr wm_socket_init(Wm *wm);
|
|
void wm_socket_cleanup(Wm *wm);
|
|
void wm_settings_message_parse(Wm *wm, char *c, int len);
|
|
|
|
void wm_sigint_handler(Wm *wm, int signum);
|
|
|
|
#endif
|