Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent centered mode (aka "Sticky Centering") #482

Merged
merged 30 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e6b5f37
sticky center
hedning Aug 15, 2020
d54c6fc
Merge remote-tracking branch 'upstream/develop' into sticky-center
jtaala Mar 3, 2023
2e9e312
Updated sticky-center branch to latest code (and latest centering
jtaala Mar 3, 2023
9df98aa
Pressing the center-horizontally shortcut again results in
jtaala Mar 3, 2023
c2a33cd
Merge remote-tracking branch 'upstream/develop' into sticky-center
jtaala Mar 3, 2023
54afadb
Added FocusModes and new bindsym "toggle-focus-mode". Updated schema.
jtaala Mar 5, 2023
a74ecd9
Entering center mode now also centers selectedWindow as well.
jtaala Mar 5, 2023
1d82adf
Added simple "focus mode" icon in topbar (which shows current focus
jtaala Mar 5, 2023
75c48a9
Focus mode icon is now clickable and cycles through focus modes when
jtaala Mar 5, 2023
2f565f4
Now using a FocusIcon class to encapsulate icon logic. Added icon to
jtaala Mar 7, 2023
066b779
Hides space icons during normal view (designed to be shown during
jtaala Mar 7, 2023
215a722
Refactor naming to refer to "focus modes" in shortcuts and internally.
jtaala Mar 7, 2023
fbd225d
Merge branch 'develop' into sticky-center
jtaala Mar 11, 2023
4ddd68b
Switching back normal focus mode (from centering mode) will move the
jtaala Mar 11, 2023
a8577a1
Now uncentering treats the first or last window specially, lines up with
jtaala Mar 12, 2023
04aa77a
Refactor topbar.focusButton. Moved to after workspace name. Now the…
jtaala Mar 12, 2023
8e1f449
Small improvements to setters in FocusModeIcon.
jtaala Mar 12, 2023
bab268d
Refactor of space focus mode elements to allow clickability (on
jtaala Mar 12, 2023
96afb74
Workspace names on other monitors (e.g. secondary monitor etc.) is now
jtaala Mar 12, 2023
98409c1
Improved click detection of space elements. Refactor and moved
jtaala Mar 13, 2023
4ff5a15
Added dconf settable setting to show/hide the new focus mode icon (in
jtaala Mar 13, 2023
367f4b0
Now packaging focus mode icons instead of relying on system icons (which
jtaala Mar 13, 2023
50c8ca0
Cleanup and removal of unneeded code (from icon loading test).
jtaala Mar 13, 2023
a686b09
Added a focus mode icon "tooltip" (my version of one anyway).
jtaala Mar 14, 2023
0776e87
FIX: focus mode icon tooltip now showing on correct monitor (in
jtaala Mar 14, 2023
06f505a
Moved tooltip to FocusIcon. Now shows for other monitors too. Added
jtaala Mar 15, 2023
efbb81b
Update resources/ICONS.info
jtaala Mar 16, 2023
a67439f
Updated README.md with a section on focus modes (with picture). Adde…
jtaala Mar 16, 2023
5c5b215
Merge remote-tracking branch 'upstream/develop' into sticky-center
jtaala Mar 16, 2023
0153216
Small change to README.md.
jtaala Mar 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions minimap.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ var Minimap = class Minimap extends Array {
}

this.layout();
let time = animate ? 0.25 : 0;
let time = animate ? prefs.animation_time : 0;
this.actor.show();
Tweener.addTween(this.actor,
{opacity: 255, time, mode: Clutter.AnimationMode.EASE_OUT_EXPO});
Expand All @@ -131,7 +131,7 @@ var Minimap = class Minimap extends Array {
hide(animate) {
if (this.destroyed)
return;
let time = animate ? 0.25 : 0;
let time = animate ? prefs.animation_time : 0;
Tweener.addTween(this.actor,
{opacity: 0, time, mode: Clutter.AnimationMode.EASE_OUT_EXPO,
onComplete: () => this.actor.hide() });
Expand Down
5 changes: 5 additions & 0 deletions resources/ICONS.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SVG icons adapted from "GNOME Project" adwaita-icon-theme (https://github.com/GNOME/adwaita-icon-theme).

See http://www.gnome.org for more information.

Please see terms, under which these icons have been copied, at https://github.com/GNOME/adwaita-icon-theme/blob/master/COPYING.
jtaala marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 4 additions & 3 deletions stylesheet.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.space-label-wrapper {
padding: 0 12px 0 0;
padding: 0 10px 0 0;
background-color: transparent;
border-image: none;
background-image: none;
Expand All @@ -8,12 +8,13 @@

.space-focus-mode-icon {
icon-size: 16px;
padding: 0px 21px 0 21px;
padding: 0 18px 0 18px;
margin-left: 3px;
background-color: transparent;
}

.focus-button-tooltip {
background-color: rgba(0, 0, 0, 0.35);
background-color: rgba(0, 0, 0, 0.7);
padding: 8px;
border-radius: 8px;
font-weight: 600;
Expand Down
3 changes: 1 addition & 2 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ var Space = class Space extends Array {
// default focusMode (can be overriden by saved user pref in Space.init method)
this.focusMode = FocusModes.DEFAULT;
this.focusModeIcon = new TopBar.FocusIcon({
reactive: true,
name: 'panel',
style_class: 'space-focus-mode-icon',
})
Expand Down Expand Up @@ -1683,7 +1682,7 @@ var Spaces = class Spaces extends Map {
* Ensures correct window layout with multi-monitors, and if windows already exist on init,
* (e.g. resetting gnome-shell) then will ensure selectedWindow is activated.
*/
imports.mainloop.timeout_add(0, () => {
imports.mainloop.timeout_add(200, () => {
const space = spaces.getActiveSpace();
if (space.selectedWindow) {
space.layout(false);
Expand Down
107 changes: 58 additions & 49 deletions topbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,20 @@ class ColorEntry {
*/
var FocusIcon = Utils.registerClass(
class FocusIcon extends St.Icon {
_init(properties = {}) {
_init(properties = {}, tooltip_x_point=0) {
super._init(properties);
this.reactive = true;

// allow custom x position for tooltip
this.tooltip_x_point = tooltip_x_point;

// read in focus icons from resources folder
this.gIconDefault = Gio.icon_new_for_string(`${Path}/resources/focus-mode-default-symbolic.svg`);
this.gIconCenter = Gio.icon_new_for_string(`${Path}/resources/focus-mode-center-symbolic.svg`);

this._initToolTip();
this.setMode();

this.connect('button-press-event', () => {
if (this.clickFunction) {
this.clickFunction();
Expand All @@ -224,19 +231,65 @@ class FocusIcon extends St.Icon {
this.clickFunction = clickFunction;
return this;
}

_initToolTip() {
const tt = new St.Label({style_class: 'focus-button-tooltip'});
tt.hide();
global.stage.add_child(tt);
this.connect('enter-event', icon => {
this._updateTooltipPosition(this.tooltip_x_point);
this._updateTooltipText();
tt.show();
});
this.connect('leave-event', (icon, event) => {
if (!this.has_pointer) {
tt.hide();
}
});
this.tooltip = tt;
}

/**
* Updates tooltip position relative to this button.
*/
_updateTooltipPosition(xpoint=0) {
//const offset = Tiling.spaces.getActiveSpace().width;
let point = this.apply_transform_to_point(
new Clutter.Vertex({x: xpoint, y: 0}));
this.tooltip.set_position(Math.max(0, point.x - 62), point.y + 34);
}

_updateTooltipText() {
const markup = (color, mode) => {
this.tooltip.clutter_text
.set_markup(
` <i>Window focus mode</i>
Current mode: <span foreground="${color}"><b>${mode}</b></span>`);
};
if (this.mode === Tiling.FocusModes.DEFAULT) {
markup('#6be67b', 'DEFAULT');
}
else if (this.mode === Tiling.FocusModes.CENTER) {
markup('#6be6cb', 'CENTER');
} else {
this.tooltip.set_text('');
}
}

/**
* Set the mode that this icon will display.
* @param {Tiling.FocusModes} mode
*/
setMode(mode) {
mode = mode ?? Tiling.FocusModes.DEFAULT;
this.mode = mode;
if (mode === Tiling.FocusModes.DEFAULT) {
this.gicon = this.gIconDefault;
}
else if (mode === Tiling.FocusModes.CENTER) {
this.gicon = this.gIconCenter;
}
this._updateTooltipText()
return this;
}

Expand All @@ -256,66 +309,23 @@ class FocusButton extends PanelMenu.Button {
_init() {
super._init(0.0, 'FocusMode');

this.focusMode = Tiling.FocusModes.DEFAULT;
this._icon = new FocusIcon({
reactive: true,
style_class: 'system-status-icon'
});
this._initToolTip();
style_class: 'system-status-icon focus-mode-button'
}, -10);

this.setFocusMode(this.focusMode);
this.setFocusMode();
this.add_child(this._icon);
this.connect('event', this._onClicked.bind(this));
this.connect('notify::allocation', () => {
let point = this._icon.apply_transform_to_point(new Clutter.Vertex({x: 0, y: 0}));
let pos = this.get_position();
log('position', pos.x, pos.y);
});
}

_initToolTip() {
const tt = new St.Label({style_class: 'focus-button-tooltip'});
tt.hide();
global.stage.add_child(tt);
this._icon.connect('enter-event', icon => {
this._setTooltipText();
tt.show();
});
this._icon.connect('leave-event', icon => {
tt.hide();
});
this.tooltip = tt;
}

setTooltipPosition(x, y) {
this.tooltip.set_position(x, y);
}

_setTooltipText() {
const markup = (color, mode) => {
this.tooltip.clutter_text
.set_markup(
` <i>Window focus mode</i>
Current mode: <span foreground="${color}"><b>${mode}</b></span>`);
};
if (this.focusMode == Tiling.FocusModes.DEFAULT) {
markup('#6be67b', 'DEFAULT');
}
else if (this.focusMode == Tiling.FocusModes.CENTER) {
markup('#6be6cb', 'CENTER');
} else {
this.tooltip.set_text('');
}
}

/**
* Sets the focus mode with this button.
* @param {*} mode
*/
setFocusMode(mode) {
mode = mode ?? Tiling.FocusModes.DEFAULT;
this.focusMode = mode;
this._icon.setMode(mode);
this._setTooltipText()
return this;
}

Expand Down Expand Up @@ -659,7 +669,6 @@ function enable () {
const pos = focusButton.apply_relative_transform_to_point(panel,
new Clutter.Vertex({ x: 0, y: 0 }));
Tiling.spaces.setFocusIconPosition(pos.x, pos.y);
focusButton.setTooltipPosition(Math.max(0, pos.x - 56), pos.y + 34);
});
fixFocusModeIcon();

Expand Down