Skip to content

Commit

Permalink
Added (configurable) padding between tiles. Fixes timbertson#20
Browse files Browse the repository at this point in the history
  • Loading branch information
timbertson committed May 14, 2012
1 parent 188bd33 commit 5bae1b2
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -4,7 +4,7 @@ spec=0launch --not-before=0.4 http://gfxmonk.net/dist/0install/coffee-spec.xml
markdown=0launch http://gfxmonk.net/dist/0install/markdown.xml
template=0launch http://gfxmonk.net/dist/0install/template.xml

all: js shellshape/schemas
all: js schemas

schemas: phony
make -C schemas
Expand All @@ -13,7 +13,7 @@ js: phony
${coffee} --bare -c shellshape/tiling.coffee

test: phony js
${spec} -vc tests
${spec} -v tests

auto: phony js
${watchdog} tricks .tricks.yaml
Expand Down
Binary file modified schemas/gschemas.compiled
Binary file not shown.
Expand Up @@ -6,6 +6,11 @@
<summary>Stop auto-tiling new windows when there are this many windows already tiled.</summary>
<description/>
</key>
<key type="i" name="tile-padding">
<default>0</default>
<summary>Padding (in px) between layout tiles.</summary>
<description/>
</key>
<key type="s" name="default-layout">
<choices>
<choice value="floating"/>
Expand Down
22 changes: 19 additions & 3 deletions shellshape/extension.js
Expand Up @@ -438,27 +438,43 @@ const Ext = function Ext() {
let name = default_layout.get();
let new_layout = LAYOUTS[name];
if(new_layout) {
self.log.info("updating default layout to " + name);
self.log.debug("updating default layout to " + name);
Workspace.prototype.default_layout = new_layout;
} else {
self.log.warn("Unknown layout name: " + name);
self.log.error("Unknown layout name: " + name);
}
};
self.connect_and_track(self, default_layout.gsettings, 'changed::' + default_layout.key, update);
update();
})();


// max-autotile
(function() {
let pref = self.prefs.MAX_AUTOTILE;
let update = function() {
let val = pref.get();
self.log.info("setting max-autotile to " + val);
self.log.debug("setting max-autotile to " + val);
Workspace.prototype.max_autotile = val;
};
self.connect_and_track(self, pref.gsettings, 'changed::' + pref.key, update);
update();
})();


// padding
(function() {
let pref = self.prefs.PADDING;
let update = function() {
let val = pref.get();
self.log.debug("setting padding to " + val);
Tiling.BaseLayout.prototype.padding = val;
self.current_workspace().relayout();
};
self.connect_and_track(self, pref.gsettings, 'changed::' + pref.key, update);
update();
})();

};

/* -------------------------------------------------------------
Expand Down
37 changes: 37 additions & 0 deletions shellshape/prefs.js
Expand Up @@ -107,6 +107,43 @@ function buildPrefsWidget() {
vbox.add(hbox);
})();



(function() {
let hbox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
spacing: 20
});

let label = new Gtk.Label({ label: "Padding between tiles (px)" });
let adjustment = new Gtk.Adjustment({
lower: 0,
upper: 20,
step_increment: 1
});
let scale = new Gtk.HScale({
digits:0,
adjustment: adjustment,
value_pos: Gtk.PositionType.RIGHT
});

hbox.add(label);
hbox.pack_end(scale, true, true, 0);
vbox.add(hbox);

var pref = config.PADDING;
scale.set_value(pref.get());
scale.connect('value-changed', function(sw) {
var oldval = pref.get();
var newval = sw.get_value();
if (newval != pref.get()) {
pref.set(newval);
}
});
})();



let label = new Gtk.HSeparator();
vbox.add(label);

Expand Down
6 changes: 6 additions & 0 deletions shellshape/shellshape_settings.js
Expand Up @@ -107,4 +107,10 @@ function Prefs() {
get: function() { return settings.get_string(this.key); },
set: function(v) { settings.set_string(this.key, v); },
};
this.PADDING = {
key: 'tile-padding',
gsettings: settings,
get: function() { return settings.get_int(this.key); },
set: function(v) { settings.set_int(this.key, v); },
};
};
36 changes: 22 additions & 14 deletions shellshape/tiling.coffee
Expand Up @@ -22,21 +22,26 @@ get_mouse_position = ->
throw "override get_mouse_position()"

Tile = {

copy_rect: (rect) ->
return {pos:{x:rect.pos.x, y:rect.pos.y}, size:{x:rect.size.x, y:rect.size.y}}

split_rect: (rect, axis, ratio) ->
split_rect: (rect, axis, ratio, padding) ->
padding ||= 0
# log("#split_rect: splitting rect of " + j(rect) + " along the " + axis + " axis with ratio " + ratio)
if(ratio > 1 || ratio < 0)
throw("invalid ratio: " + ratio + " (must be between 0 and 1)")
new_size_a = rect.size[axis] * ratio
new_size_a = Math.round(rect.size[axis] * ratio)
new_size_b = rect.size[axis] - new_size_a

padding = Math.round(Math.min((new_size_a / 2), (new_size_b / 2), padding))
# log("effective padding is " + padding)

new_rect = Tile.copy_rect(rect)
rect = Tile.copy_rect(rect)
rect.size[axis] = new_size_a
new_rect.size[axis] = new_size_b
new_rect.pos[axis] += new_size_a
rect.size[axis] = new_size_a - padding
new_rect.size[axis] = new_size_b - padding
new_rect.pos[axis] += new_size_a + padding
# log("rect copy: " + j(rect))
# log("new_rect: " + j(new_rect))
return [rect, new_rect]
Expand Down Expand Up @@ -312,13 +317,13 @@ class BaseSplit
@ratio = new_ratio

class Split extends BaseSplit
layout_one: (rect, windows) ->
layout_one: (rect, windows, padding) ->
@save_last_rect(rect)
first_window = windows.shift()
if windows.length == 0
first_window.set_rect(rect)
return [{}, []]
[window_rect, remaining] = Tile.split_rect(rect, @axis, @ratio)
[window_rect, remaining] = Tile.split_rect(rect, @axis, @ratio, padding)
first_window.set_rect(window_rect)
return [remaining, windows]

Expand Down Expand Up @@ -353,12 +358,12 @@ class MultiSplit extends BaseSplit
@log = Log.getLogger("shellshape.tiling.MultiSplit")
super(axis)

split: (bounds, windows) ->
split: (bounds, windows, padding) ->
@save_last_rect(bounds)
# @log.debug("mainsplit: dividing #{windows.length} after #{@primary_windows} for bounds #{j bounds}")
[left_windows, right_windows] = @partition_windows(windows)
if left_windows.length > 0 and right_windows.length > 0
[left_rect, right_rect] = Tile.split_rect(bounds, @axis, @ratio)
[left_rect, right_rect] = Tile.split_rect(bounds, @axis, @ratio, padding)
else
# only one side wil actually be laid out...
[left_rect, right_rect] = [bounds, bounds]
Expand All @@ -372,6 +377,7 @@ class MultiSplit extends BaseSplit
idx < @primary_windows

class BaseLayout
padding: 0
constructor: (state) ->
@state = state
@tiles = state.tiles
Expand Down Expand Up @@ -506,16 +512,17 @@ class BaseTiledLayout extends BaseLayout
@tiles.each_tiled(func)

layout: (accommodate_window) ->
padding = @padding
layout_windows = @tiles.for_layout()
@log.debug("laying out #{layout_windows.length} windows")
if accommodate_window?
@_change_main_ratio_to_accommodate(accommodate_window, @main_split)
[left, right] = @main_split.split(@bounds, layout_windows)
[left, right] = @main_split.split(@bounds, layout_windows, padding)
# @log.debug("split screen into rect #{j left[0]} | #{j right[0]}")
@_layout_side(left..., @splits.left, accommodate_window)
@_layout_side(right..., @splits.right, accommodate_window)
@_layout_side(left..., @splits.left, accommodate_window, padding)
@_layout_side(right..., @splits.right, accommodate_window, padding)

_layout_side: (rect, windows, splits, accommodate_window) ->
_layout_side: (rect, windows, splits, accommodate_window, padding) ->
axis = Axis.other(@main_axis)

extend_to = (size, array, generator) ->
Expand All @@ -541,7 +548,7 @@ class BaseTiledLayout extends BaseLayout
previous_split = null
for [window, split] in zip(windows, splits)
window.top_split = previous_split
[rect, windows] = split.layout_one(rect, windows)
[rect, windows] = split.layout_one(rect, windows, padding)
window.ensure_within(@bounds)
window.bottom_split = if (windows.length > 0) then split else null
previous_split = split
Expand Down Expand Up @@ -834,6 +841,7 @@ class TiledWindow

set_rect : (r) ->
# log("offset rect to " + j(@offset))
# @log.debug("tile has new rect: " + j(r))
@_resize(r.size)
@_move(r.pos)
@layout()
Expand Down
35 changes: 20 additions & 15 deletions shellshape/tiling.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions shellshape/workspace.js
Expand Up @@ -107,10 +107,10 @@ Workspace.prototype = {
for(let i=0; i<keys.length; i++) {
this[keys[i]] = other[keys[i]];
}
this._relayout();
this.relayout();
},

_relayout: _duck_overview(function() {
relayout: _duck_overview(function() {
this.layout.layout();
}),

Expand Down

0 comments on commit 5bae1b2

Please sign in to comment.