Skip to content

Commit

Permalink
ntwm v1.2.6: Replace linked list implementation with memory pool (bri…
Browse files Browse the repository at this point in the history
…nging speedups), other small fixes/changes
  • Loading branch information
Cubified committed Mar 10, 2019
1 parent 6e694a2 commit 3577860
Show file tree
Hide file tree
Showing 13 changed files with 479 additions and 392 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ all: config.h ntwm

CC=gcc

CFLAGS=-Iinclude -Iconfig
CFLAGS=-Iinclude -Iconfig -Wno-pointer-to-int-cast
LIBS=-lX11 -lXrandr

FLAGS=-Os -pipe -s -ansi -pedantic
FLAGS=-Os -s -pipe -ansi -pedantic
DEBUGFLAGS=-Og -Wall -pipe -g -ansi -pedantic

SOURCES=ntwm.c
Expand Down
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![ntwm](https://github.com/Cubified/ntwm/blob/master/images/ntwm.png)

# ntwm v1.2.5
# ntwm v1.2.6

A tiny, frameless, keyboard-driven tiling window manager with multimonitor support.

Expand All @@ -18,8 +18,8 @@ All of the following window managers have multimonitor support.

| ntwm | 19kb |
|------|-------|
| dwm | 33kb |
| 2bwm | 36kb |
| dwm | 46kb |
| i3 | 343kb |

*(Note: these values are approximate and may be subject to change)*
Expand Down Expand Up @@ -146,10 +146,33 @@ By default, ntwm supports the following tiling modes (with more coming):

To edit the order in which these modes are selected, adjust the `modes` variable in `config.h`.

However, if you'd like to shrink the size of the output binary, you may remove support for additional modes by removing the corresponding `ENABLE_*` preprocessor definition.

### Logging

To further decrease filesize, ntwm supports compilation without `stdio.h`, resulting in a save of approximately 4kb. To enable this, define `LOGGING_NO_STDIO` in `config.h`.

### Memory Usage

With v1.2.6, ntwm now supports user-configurable memory usage through the `MAX_MONITORS`, `MAX_WINDOWS`, and `MAX_BARS` directives - ensuring ntwm will use exactly the amount of memory required to hold the given amounts of each.

Tune these to your system, but ensure they are not overly constraining - exceeding them will invoke unwanted behavior.

### Towards an Even Smaller Binary

In no particular order:
- Run [sstrip](http://www.muppetlabs.com/~breadbox/software/elfkickers.html) (19kb -> 17kb)
- Compile with [musl](https://www.musl-libc.org) or [dietlibc](https://www.fefe.de/dietlibc) (requires Xlib and any other userland X applications to be compiled from source)
- Compile a 32-bit binary (requires 32-bit Xlib)

---

## Changelog

### v1.2.6
- Replace linked list implementation with `libspool.h`, increasing filesize but treating memory more responsibly and executing more quickly
- Allow for the disabling of certain tiling modes, decreasing filesize

### v1.2.5
- Add support for two types of client message (`NET_WM_STATE_ABOVE` and `NET_WM_STATE_FULLSCREEN`) with more to come
- Add global "above" window which supersedes per-monitor fullscreen
Expand All @@ -158,6 +181,7 @@ To edit the order in which these modes are selected, adjust the `modes` variable
- Move all Xlib utility functions into `x.h`
- Move files into appropriate folders, cleaning up the appearance of the repository
- Add `above_enabled` check to avoid X error
- Add support for logging without `stdio.h` (error messages are somewhat less specific, but still useful)

### v1.2.0
- Add support for pre-mapped windows being tiled, thereby greatly improving the `reset` command
Expand Down Expand Up @@ -225,8 +249,8 @@ To edit the order in which these modes are selected, adjust the `modes` variable

## To-Do

- Investigate and resolve any remaining memory leaks
- Fix flickering upon dragging chromium tabs
- Clean up tiling functionality
- Fix support for dual bars
- Fix incongruency between client-toggled and window manager-wide fullscreen

## What Will (Likely) Never be Implemented
Expand Down
13 changes: 11 additions & 2 deletions config/config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
* config.h: ntwm configuration
*/

#define VER "1.2.5"
#define VER "1.2.6"
#define GAPS 50
#define STACK_RATIO 0.3
#define DIALOG_RATIO 0.7
#define MULTIHEAD /* multimonitor support */
#define LOGGING /* startup/shutdown logging */
/*#define LOGGING_NO_STDIO*/ /* avoid including stdio.h for error/info logging (decreases filesize) */
#define MASK Mod1Mask
#define SHIFT ShiftMask

#define MAX_MONITORS 2 /* memory fine-tuning options - ntwm will use no more memory than is specified here */
#define MAX_WINDOWS 16
#define MAX_BARS 2

#define TERMCMD "xterm"

char *autostartcmd = "true";
Expand Down Expand Up @@ -53,6 +57,11 @@ const key keys[] = {

typedef void (*func)();

#define ENABLE_GRID
#define ENABLE_DUALSTACK
#define ENABLE_FIBONACCI
#define ENABLE_BOTTOMSTACK

static void tile_grid();
static void tile_dualstack();
static void tile_fibonacci();
Expand Down
37 changes: 20 additions & 17 deletions include/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ void map_request(XEvent *e){
if((wintype == window_normal ||
wintype == window_utility) &&
!x_is_child(ev->window)){
node *list = find_monitor()->windows;
pool *list = find_monitor()->windows;

if(list_find(list, NULL, ev->window) == NULL){
node *n = list_push(list);
n->data_noptr = ev->window;
if(pool_find((void*)ev->window, list) == -1){
pool_push((void*)ev->window, list);

tile();

Expand Down Expand Up @@ -95,14 +94,14 @@ void configure_request(XEvent *e){
*/
void unmap_notify(XEvent *e){
XUnmapEvent *ev = &e->xunmap;
node *list = find_monitor()->windows;
node *elem = list_find(list,NULL,ev->window);
pool *list = find_monitor()->windows;
int ind = pool_find((void*)ev->window, list);

last_call = "unmap";

if(focused == ev->window){
if(list->size > 1){
cycle_windows(list,focused,0);
if((unsigned int)~list->avail > 0){
cycle_windows(list, focused, 0);
} else {
focused = 0;
}
Expand All @@ -113,16 +112,16 @@ void unmap_notify(XEvent *e){
above = 0;
}

if(elem != NULL){
list_pop(list,elem);
tile();
if(ind > -1){
pool_pop(ind, list);
} else {
node *bar = list_find(bars,NULL,ev->window);
if(bar != NULL){
multihead_delbar(bar->data_noptr);
tile();
int p;
if((p = pool_find((void*)ev->window, bars)) > -1){
multihead_delbar(p);
}
}

tile();
}

/*
Expand Down Expand Up @@ -157,10 +156,10 @@ void key_press(XEvent *e){
toggle_fullscreen(current_monitor, focused);
break;
case cmd_next:
cycle_monitors(focused, 1);
cycle_monitors(focused, DIR_RIGHT);
break;
case cmd_prev:
cycle_monitors(focused, 0);
cycle_monitors(focused, DIR_LEFT);
break;
case cmd_mode:
next_mode();
Expand All @@ -175,7 +174,11 @@ void key_press(XEvent *e){
reset(map_request);
break;
default:
#ifdef LOGGING_NO_STDIO
error("Unrecognized command in config.");
#else
error("Unrecognized command \"%s\" in config.", keys[i].func);
#endif
break;
}
}
Expand Down
Loading

0 comments on commit 3577860

Please sign in to comment.