~zenomat/dwm-gnome

e433d6a53f4c7a78f98f4f38ed259e3a9d91b851 — zeno 8 months ago ed2332d
add, remove window: abstract functionallity further

add `addWindow()` and `removeWindow()` functions, that figure out on
their own, wether they are deleting the master or a stack window. this
way the window manager doesn't have to do this every time he wants to
add/remove a window
1 files changed, 40 insertions(+), 25 deletions(-)

M extension.js
M extension.js => extension.js +40 -25
@@ 72,6 72,16 @@ class WindowManager {
		this.activeWorkspace.master.prev = newWin;
	}

	addWindow(win) {
		// no window is present:
		if (this.activeWorkspace.master == null) {
			this.addMaster(win);
		// if master is the only window
		} else {
			this.addNewAtBottom(win);
		}
	}

	removeMasterWhenSingle() {
		this.activeWorkspace.master.destroy();
		this.activeWorkspace.master = null;


@@ 89,7 99,7 @@ class WindowManager {
		this.activeWorkspace.master = newMaster;
	}

	removeWindow(win) {
	removeStackWindow(win, destroy) {
		let currentWindow = this.activeWorkspace.master;

		// go through all the windows, searching for the one that was deleted


@@ 100,14 110,39 @@ class WindowManager {
				currentWindow.prev.next = currentWindow.next;
				// the next widnow of the deleted should point to the prev of the deleted, skipping it
				currentWindow.next.prev = currentWindow.prev;
				// set to null, gc
				currentWindow.destroy();
				if (destroy) {
					// set to null, gc
					currentWindow.destroy();
				}
				break;
			}
			currentWindow = currentWindow.next;
		} while (currentWindow != this.activeWorkspace.master);
	}

	removeWindow(win) {
		// // because we call this event
		// if (this.activeWorkspace.master == null) {
		// 	return;
		// }
		// remove the master window
		if (win == this.activeWorkspace.master.win) {
			log('Removing the master window');
			// the master window is the only one
			if (this.activeWorkspace.master.next == this.activeWorkspace.master) {
				log('Master is the only window');
				this.removeMasterWhenSingle();
			} else {
				log('There are other windows');
				this.removeMaster();
			}
		// remove window from stack
		} else {
			this.removeStackWindow(win, true);
		}
	}


	computeAndPosition() {
		log(`Arranging ${this.activeWorkspace.windowCount} windows`);



@@ 186,14 221,7 @@ class WindowManager {
		let window = new Window(win);

		// add new window to the linked list
		//
		// no window is present:
		if (this.activeWorkspace.master == null) {
			this.addMaster(win);
		// if master is the only window
		} else {
			this.addNewAtBottom(win);
		}
		this.addWindow(win);
		this.activeWorkspace.windowCount++;

		// connect to the a signal, that fires, before the window is drawn


@@ 211,20 239,7 @@ class WindowManager {
	windowDestroyed(display, win) {
		log('Deleting window');

		// remove the master window
		if (win == this.activeWorkspace.master.win) {
			log('Removing the master window');
			// the master window is the only one
			if (this.activeWorkspace.master.next == this.activeWorkspace.master) {
				log('Master is the only window');
				this.removeMasterWhenSingle();
			} else {
				log('There are other windows');
				this.removeMaster();
			}
		} else {
			this.removeWindow(win);
		}
		this.removeWindow(win);
		this.activeWorkspace.windowCount--;

		// reposition all windows