summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/defs.h6
-rw-r--r--src/parser.c22
-rw-r--r--src/sxwm.c45
3 files changed, 49 insertions, 24 deletions
diff --git a/src/defs.h b/src/defs.h
index 27d16fd..5750a05 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -20,7 +20,7 @@
#define UDIST(a, b) abs((int)(a) - (int)(b))
#define CLAMP(x, lo, hi) (((x) < (lo)) ? (lo) : ((x) > (hi)) ? (hi) : (x))
#define MAX_CLIENTS 99
-#define MAX_SCRATCHPADS 20
+#define MAX_SCRATCHPADS 32
#define MIN_WINDOW_SIZE 20
#define MAX_ITEMS 256
#define BIND(mod, key, cmdstr) {(mod), XK_##key, {cmdstr}, False}
@@ -108,8 +108,8 @@ typedef struct {
char **should_float[MAX_ITEMS];
char **start_fullscreen[MAX_ITEMS];
char **can_swallow[MAX_ITEMS];
- char **can_be_swallowed[MAX_ITEMS];
- char **scratchpads[32];
+ char **can_be_swallowed[MAX_ITEMS];
+ char **scratchpads[MAX_SCRATCHPADS];
char **open_in_workspace[MAX_ITEMS];
char *to_run[MAX_ITEMS];
} Config;
diff --git a/src/parser.c b/src/parser.c
index 6bfaeeb..adda1b5 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -105,7 +105,7 @@ static unsigned parse_combo(const char *combo, Config *cfg, KeySym *out_ks)
{
unsigned m = 0;
KeySym ks = NoSymbol;
- char buf[256];
+ char buf[MAX_ITEMS];
strncpy(buf, combo, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
@@ -195,7 +195,7 @@ found:
int to_run = 0;
/* Initialize should_float matrix */
- for (int j = 0; j < 256; j++) {
+ for (int j = 0; j < MAX_ITEMS; j++) {
cfg->should_float[j] = calloc(2, sizeof(char *));
if (!cfg->should_float[j]) {
goto cleanup_file;
@@ -268,7 +268,7 @@ found:
cfg->snap_distance = atoi(rest);
}
else if (!strcmp(key, "should_float")) {
- if (should_floatn >= 256) {
+ if (should_floatn >= MAX_ITEMS) {
fprintf(stderr, "sxwmrc:%d: too many should_float entries\n", lineno);
continue;
}
@@ -287,7 +287,7 @@ found:
char *comma = strtok_r(final, ",", &comma_ptr);
/* store each comma separated value in a seperate row */
- while (comma && should_floatn < 256) {
+ while (comma && should_floatn < MAX_ITEMS) {
comma = strip(comma);
if (*comma == '"') {
comma++;
@@ -433,7 +433,7 @@ found:
}
}
else if (!strcmp(key, "exec")) {
- if (to_run >= 256) {
+ if (to_run >= MAX_ITEMS) {
fprintf(stderr, "sxwmrc:%d: too many exec commands\n", lineno);
continue;
}
@@ -461,7 +461,7 @@ found:
else if (!strcmp(key, "can_swallow")) {
char *token = strtok(rest, ",");
int i = 0;
- while (token && i < 256) {
+ while (token && i < MAX_ITEMS) {
char *item = strip_quotes(strip(token));
if (*item) {
cfg->can_swallow[i] = malloc(2 * sizeof(char *));
@@ -479,7 +479,7 @@ found:
else if (!strcmp(key, "can_be_swallowed")) {
char *token = strtok(rest, ",");
int i = 0;
- while (token && i < 256) {
+ while (token && i < MAX_ITEMS) {
char *item = strip_quotes(strip(token));
if (*item) {
cfg->can_be_swallowed[i] = malloc(2 * sizeof(char *));
@@ -516,7 +516,7 @@ found:
/* find free slot in open_in_workspace */
int slot = -1;
- for (int i = 0; i < 256; i++) {
+ for (int i = 0; i < MAX_ITEMS; i++) {
if (!cfg->open_in_workspace[i]) {
slot = i;
break;
@@ -549,7 +549,7 @@ found:
int start_fullscreen_idx = 0;
/* find first empty slot */
- for (int i = 0; i < 256; i++) {
+ for (int i = 0; i < MAX_ITEMS; i++) {
if (!cfg->start_fullscreen[i]) {
start_fullscreen_idx = i;
break;
@@ -557,7 +557,7 @@ found:
}
/* store each comma separated value in a separate row */
- while (comma && start_fullscreen_idx < 256) {
+ while (comma && start_fullscreen_idx < MAX_ITEMS) {
comma = strip(comma);
if (*comma == '"') {
comma++;
@@ -600,7 +600,7 @@ cleanup_file:
if (f) {
fclose(f);
}
- for (int j = 0; j < 256; j++) {
+ for (int j = 0; j < MAX_ITEMS; j++) {
if (cfg->should_float[j]) {
free(cfg->should_float[j][0]);
free(cfg->should_float[j]);
diff --git a/src/sxwm.c b/src/sxwm.c
index 843b133..8a16b11 100644
--- a/src/sxwm.c
+++ b/src/sxwm.c
@@ -89,6 +89,7 @@ void remove_scratchpad(int n);
/* void resize_stack_add(void); */
/* void resize_stack_sub(void); */
void run(void);
+void reset_opacity(Window w);
void scan_existing_windows(void);
void select_input(Window w, Mask masks);
void send_wm_take_focus(Window w);
@@ -96,6 +97,7 @@ void setup(void);
void setup_atoms(void);
void set_frame_extents(Window w);
void set_input_focus(Client *c, Bool raise_win, Bool warp);
+void set_opacity(Window w, double opacity);
void set_win_scratchpad(int n);
int snap_coordinate(int pos, int size, int screen_size, int snap_dist);
void spawn(const char * const *argv);
@@ -1106,7 +1108,7 @@ void hdl_map_req(XEvent *xev)
}
if (open_windows == MAX_CLIENTS) {
- printf("sxwm: max clients reached, ignoring map request\n");
+ fprintf(stderr, "sxwm: max clients reached, ignoring map request\n");
return;
}
@@ -1458,13 +1460,13 @@ Bool is_child_proc(pid_t parent_pid, pid_t child_pid)
snprintf(path, sizeof(path), "/proc/%d/stat", current_pid);
f = fopen(path, "r");
if (!f) {
- printf("sxwm: could not open %s\n", path);
+ fprintf(stderr, "sxwm: could not open %s\n", path);
return False;
}
int ppid = 0;
if (fscanf(f, "%*d %*s %*c %d", &ppid) != 1) {
- printf("sxwm: failed to read ppid from %s\n", path);
+ fprintf(stderr, "sxwm: failed to read ppid from %s\n", path);
fclose(f);
return False;
}
@@ -1476,7 +1478,7 @@ Bool is_child_proc(pid_t parent_pid, pid_t child_pid)
if (ppid <= 1) {
/* Reached init or kernel */
- printf("sxwm: reached init/kernel, no relationship found\n");
+ fprintf(stderr, "sxwm: reached init/kernel, no relationship found\n");
break;
}
current_pid = ppid;
@@ -1720,7 +1722,7 @@ void quit(void)
XFreeCursor(dpy, cursor_move);
XFreeCursor(dpy, cursor_normal);
XFreeCursor(dpy, cursor_resize);
- printf("quitting...\n");
+ puts("quitting...");
running = False;
}
@@ -2174,6 +2176,27 @@ void set_win_scratchpad(int n)
scratchpads[n].enabled = False;
}
+void reset_opacity(Window w)
+{
+ Atom atom = XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False);
+ XDeleteProperty(dpy, w, atom);
+}
+
+
+void set_opacity(Window w, double opacity)
+{
+ unsigned long op = (unsigned long)(opacity * 0xFFFFFFFF);
+ Atom atom = XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False);
+
+ if (opacity < 0.0) {
+ opacity = 0.0;
+ }
+ if (opacity > 1.0) {
+ opacity = 1.0;
+ }
+ XChangeProperty(dpy, w, atom, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)&op, 1);
+}
+
int snap_coordinate(int pos, int size, int screen_size, int snap_dist)
{
if (UDIST(pos, 0) <= snap_dist) {
@@ -2659,10 +2682,12 @@ void toggle_fullscreen(void)
XSetWindowBorderWidth(dpy, focused->win, 0);
XMoveResizeWindow(dpy, focused->win, fs_x, fs_y, fs_w, fs_h);
XRaiseWindow(dpy, focused->win);
+ set_opacity(focused->win, 100);
}
else {
XMoveResizeWindow(dpy, focused->win, focused->orig_x, focused->orig_y, focused->orig_w, focused->orig_h);
XSetWindowBorderWidth(dpy, focused->win, user_config.border_width);
+ reset_opacity(focused->win);
if (!focused->floating) {
focused->mon = get_monitor_for(focused);
@@ -3014,7 +3039,7 @@ void xev_case(XEvent *xev)
evtable[xev->type](xev);
}
else {
- printf("sxwm: invalid event type: %d\n", xev->type);
+ fprintf(stderr, "sxwm: invalid event type: %d\n", xev->type);
}
}
@@ -3023,7 +3048,7 @@ int main(int ac, char **av)
if (ac > 1) {
if (strcmp(av[1], "-v") == 0 || strcmp(av[1], "--version") == 0) {
printf("%s\n%s\n%s\n", SXWM_VERSION, SXWM_AUTHOR, SXWM_LICINFO);
- exit(0);
+ return EXIT_SUCCESS;
}
else if (strcmp(av[1], "-b") == 0 || strcmp(av[1], "--backup") == 0) {
puts("sxwm: using backup keybinds");
@@ -3033,11 +3058,11 @@ int main(int ac, char **av)
puts("usage:\n");
puts("\t[-v || --version]: See the version of sxwm\n");
puts("\t[-b || --backup]: Use backup set of keybinds with sxwm\n");
- exit(0);
+ return EXIT_SUCCESS;
}
}
setup();
- printf("sxwm: starting...\n");
+ puts("sxwm: starting...");
run();
- return 0;
+ return EXIT_SUCCESS;
}