mirror of
https://github.com/zoriya/fairy.git
synced 2026-06-05 03:30:15 +00:00
Add set/add tags keys
This commit is contained in:
@@ -87,6 +87,83 @@
|
||||
<summary>Swap the current window with the master</summary>
|
||||
</key>
|
||||
|
||||
<key type="as" name="set-tag-1">
|
||||
<default><![CDATA[['<Super>1']]]></default>
|
||||
<summary>Set the current's monitor tag to 1</summary>
|
||||
</key>
|
||||
<key type="as" name="set-tag-2">
|
||||
<default><![CDATA[['<Super>2']]]></default>
|
||||
<summary>Set the current's monitor tag to 2</summary>
|
||||
</key>
|
||||
<key type="as" name="set-tag-3">
|
||||
<default><![CDATA[['<Super>3']]]></default>
|
||||
<summary>Set the current's monitor tag to 3</summary>
|
||||
</key>
|
||||
<key type="as" name="set-tag-4">
|
||||
<default><![CDATA[['<Super>4']]]></default>
|
||||
<summary>Set the current's monitor tag to 4</summary>
|
||||
</key>
|
||||
<key type="as" name="set-tag-5">
|
||||
<default><![CDATA[['<Super>5']]]></default>
|
||||
<summary>Set the current's monitor tag to 5</summary>
|
||||
</key>
|
||||
<key type="as" name="set-tag-6">
|
||||
<default><![CDATA[['<Super>6']]]></default>
|
||||
<summary>Set the current's monitor tag to 6</summary>
|
||||
</key>
|
||||
<key type="as" name="set-tag-7">
|
||||
<default><![CDATA[['<Super>7']]]></default>
|
||||
<summary>Set the current's monitor tag to 7</summary>
|
||||
</key>
|
||||
<key type="as" name="set-tag-8">
|
||||
<default><![CDATA[['<Super>8']]]></default>
|
||||
<summary>Set the current's monitor tag to 8</summary>
|
||||
</key>
|
||||
<key type="as" name="set-tag-9">
|
||||
<default><![CDATA[['<Super>9']]]></default>
|
||||
<summary>Set the current's monitor tag to 9</summary>
|
||||
</key>
|
||||
<key type="as" name="set-tag-all">
|
||||
<default><![CDATA[['<Super>0']]]></default>
|
||||
<summary>Activate all the tags available on the current monitor</summary>
|
||||
</key>
|
||||
|
||||
<key type="as" name="add-tag-1">
|
||||
<default><![CDATA[['<Super><Ctrl>1']]]></default>
|
||||
<summary>add the current's monitor tag to 1</summary>
|
||||
</key>
|
||||
<key type="as" name="add-tag-2">
|
||||
<default><![CDATA[['<Super><Ctrl>2']]]></default>
|
||||
<summary>add the current's monitor tag to 2</summary>
|
||||
</key>
|
||||
<key type="as" name="add-tag-3">
|
||||
<default><![CDATA[['<Super><Ctrl>3']]]></default>
|
||||
<summary>add the current's monitor tag to 3</summary>
|
||||
</key>
|
||||
<key type="as" name="add-tag-4">
|
||||
<default><![CDATA[['<Super><Ctrl>4']]]></default>
|
||||
<summary>add the current's monitor tag to 4</summary>
|
||||
</key>
|
||||
<key type="as" name="add-tag-5">
|
||||
<default><![CDATA[['<Super><Ctrl>5']]]></default>
|
||||
<summary>add the current's monitor tag to 5</summary>
|
||||
</key>
|
||||
<key type="as" name="add-tag-6">
|
||||
<default><![CDATA[['<Super><Ctrl>6']]]></default>
|
||||
<summary>add the current's monitor tag to 6</summary>
|
||||
</key>
|
||||
<key type="as" name="add-tag-7">
|
||||
<default><![CDATA[['<Super><Ctrl>7']]]></default>
|
||||
<summary>add the current's monitor tag to 7</summary>
|
||||
</key>
|
||||
<key type="as" name="add-tag-8">
|
||||
<default><![CDATA[['<Super><Ctrl>8']]]></default>
|
||||
<summary>add the current's monitor tag to 8</summary>
|
||||
</key>
|
||||
<key type="as" name="add-tag-9">
|
||||
<default><![CDATA[['<Super><Ctrl>9']]]></default>
|
||||
<summary>add the current's monitor tag to 9</summary>
|
||||
</key>
|
||||
<!-- TODO: Add fullscreen, monitors and tags key -->
|
||||
</schema>
|
||||
</schemalist>
|
||||
|
||||
+49
-14
@@ -39,16 +39,6 @@ var KeyboardManager = GObject.registerClass(
|
||||
Main.wm.removeKeybinding(key);
|
||||
}
|
||||
|
||||
_switchLayout(mode) {
|
||||
const mon = global.display.get_current_monitor();
|
||||
const state = this._state.monitors[mon];
|
||||
const currentLayout = state.layout;
|
||||
if (state.layout === mode) state.layout = state.oldLayout;
|
||||
else state.layout = mode;
|
||||
state.oldLayout = currentLayout;
|
||||
this._renderer.render(mon);
|
||||
}
|
||||
|
||||
enable() {
|
||||
this._addBinding("set-layout-tiling", () => this._switchLayout("tiling"));
|
||||
this._addBinding("set-layout-monocle", () =>
|
||||
@@ -118,13 +108,42 @@ var KeyboardManager = GObject.registerClass(
|
||||
const idx = this._state.workIndexByHandle(state.focused);
|
||||
|
||||
// if the master is not focused
|
||||
if (idx !== 0)
|
||||
this._state.swap(mon, state.tags, idx, 0)
|
||||
else
|
||||
this._state.swap(mon, state.tags, idx, state.beforeZoom);
|
||||
if (idx !== 0) this._state.swap(mon, state.tags, idx, 0);
|
||||
else this._state.swap(mon, state.tags, idx, state.beforeZoom);
|
||||
state.beforeZoom = idx;
|
||||
this._renderer.render(mon);
|
||||
});
|
||||
|
||||
for (const tagNbr = 1; tagNbr < 10; tagNbr++) {
|
||||
const tag = 0b1 << tagNbr;
|
||||
|
||||
this._addBinding(`set-tag-${tagNbr}`, () => {
|
||||
const mon = global.display.get_current_monitor();
|
||||
this._renderer.setTags(mon, tag);
|
||||
});
|
||||
this._addBinding(`add-tag-${tagNbr}`, () => {
|
||||
const mon = global.display.get_current_monitor();
|
||||
const currTags = this._state.monitors[mon].tags;
|
||||
// Add the tag to the monitor but if the tag is already present, remove it
|
||||
// Do not allow 0 tags to be present.
|
||||
this._renderer.setTags(
|
||||
mon,
|
||||
currTags & tag && currTags !== tag
|
||||
? currTags & ~tag
|
||||
: currTags | tag
|
||||
);
|
||||
});
|
||||
}
|
||||
this._addBinding("set-tag-all", () => {
|
||||
const mon = global.display.get_current_monitor();
|
||||
|
||||
const takkenTags = 0;
|
||||
for (const i = 0; i < this._state.monitors.length; i++)
|
||||
takkenTags |= this._state.monitors[i];
|
||||
|
||||
this._state.monitors[mon].tags |= ~takkenTags;
|
||||
this._renderer.render(mon);
|
||||
});
|
||||
}
|
||||
|
||||
disable() {
|
||||
@@ -143,6 +162,22 @@ var KeyboardManager = GObject.registerClass(
|
||||
this._removeBinding("swap-next");
|
||||
this._removeBinding("swap-prev");
|
||||
this._removeBinding("zoom");
|
||||
|
||||
for (const i = 1; i < 10; i++) {
|
||||
this._removeBinding(`set-tag-${i}`);
|
||||
this._removeBinding(`add-tag-${i}`);
|
||||
}
|
||||
this._removeBinding("set-tag-all");
|
||||
}
|
||||
|
||||
_switchLayout(mode) {
|
||||
const mon = global.display.get_current_monitor();
|
||||
const state = this._state.monitors[mon];
|
||||
const currentLayout = state.layout;
|
||||
if (state.layout === mode) state.layout = state.oldLayout;
|
||||
else state.layout = mode;
|
||||
state.oldLayout = currentLayout;
|
||||
this._renderer.render(mon);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
+36
-6
@@ -141,8 +141,7 @@ var Renderer = GObject.registerClass(
|
||||
log("Switch to tags", tags);
|
||||
if (Meta.prefs_get_workspaces_only_on_primary()) {
|
||||
const primaryMon = global.display.get_primary_monitor();
|
||||
this._state.monitors[primaryMon].tags = tags;
|
||||
this.render(primaryMon, tags);
|
||||
this.setTag(primaryMon, tags);
|
||||
} else {
|
||||
for (let i = 0; i < this._state.monitors.length; i++) {
|
||||
this._state.monitors[i].tags = tags;
|
||||
@@ -188,13 +187,44 @@ var Renderer = GObject.registerClass(
|
||||
this._state.newWindow(window);
|
||||
}
|
||||
|
||||
setTag(mon, tags) {
|
||||
const currTags = this._state.monitors[mon].tags;
|
||||
this._state.monitors[mon].tags = tags;
|
||||
this._setGWorkspaceIfNeeded(mon);
|
||||
|
||||
for (const i = 0; i < this._state.monitors.length; i++) {
|
||||
if (this._state.monitors[i] & tags && mon !== i) {
|
||||
// Remove the selected tag from other monitors.
|
||||
// If the other monitor had only this tag, swap monitor's tags instead.
|
||||
this._state.monitors[i] = this._state.monitors[i] & ~tags || currTags;
|
||||
this._setGWorkspaceIfNeeded(i);
|
||||
this.render(i);
|
||||
}
|
||||
}
|
||||
|
||||
this.render(mon);
|
||||
}
|
||||
|
||||
_setGWorkspaceIfNeeded(mon) {
|
||||
if (mon !== global.display.get_primary_monitor()) return;
|
||||
|
||||
const tags = this._state.monitors[mon].tags;
|
||||
// This retrieve the lower tag present in the tags set.
|
||||
const tag = (tags & ~(tags - 1));
|
||||
if (tags !== tag) return;
|
||||
// Retrieve the gnome workspace for the tag (inverse of 0b1 << tag)
|
||||
const workspace = Math.log2(tag) + 1;
|
||||
|
||||
global.display
|
||||
.get_workspace_manager()
|
||||
.get_workspace_by_index(workspace)
|
||||
.activate(global.display.get_current_time());
|
||||
}
|
||||
|
||||
renderAll() {
|
||||
const monN = global.display.get_n_monitors();
|
||||
// TODO: Support different tags on different monitors.
|
||||
const tags =
|
||||
global.display.get_workspace_manager().get_active_workspace_index() + 1;
|
||||
for (let mon = 0; mon < monN; mon++) {
|
||||
this.render(mon, tags);
|
||||
this.render(mon, this._state.monitors[mon].tags);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user