Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bcbad9f
Patch monitor.inFullscreen to check PaperWM spaces
Lythenas Nov 22, 2023
2143e0c
Stop hiding topbar
Lythenas Nov 22, 2023
6b5a125
Move patch to patches.js
Lythenas Nov 23, 2023
1e83182
Hide our topbar when the real one is moved onto it
Lythenas Nov 23, 2023
41bbb92
Show correct info when panel is not on primary monitor
Lythenas Nov 23, 2023
2e0f9cc
Don't shrink workarea if panel was moved to secondary monitor
Lythenas Nov 23, 2023
862c0e6
Expose paperwm in global variable
Lythenas Nov 24, 2023
a40d6d1
Fix null check
Lythenas Nov 24, 2023
03f7196
Check position of monitor instead of backdrop
Lythenas Nov 25, 2023
33acbd9
Add undefined check to patch
Lythenas Nov 25, 2023
45d14fc
Always update topbar workspace indicator during switching
Lythenas Nov 25, 2023
270b2c4
Run layout after workspace switch animation
Lythenas Nov 27, 2023
dde175b
Fix topbar when swapping workspaces
Lythenas Dec 2, 2023
718af77
Don't change topbar style when updating window position indicator
Lythenas Dec 2, 2023
ee87d11
Set topbar elements visible by default
Lythenas Dec 2, 2023
24cc09b
Hide focus mode icon if topbar is hidden on ws
Lythenas Dec 2, 2023
333b1ce
Add helper Topbar.isOnMonitor
Lythenas Dec 2, 2023
dfd39d6
Only update topbar ws name if on the same monitor
Lythenas Dec 2, 2023
b1e9391
Fix detection when window starts in fullscreen
Lythenas Dec 25, 2023
4d829a8
Queue layout after panelBox position changed
Lythenas Dec 26, 2023
6d2ae74
Merge remote-tracking branch 'upstream/develop' into fullscreen-avoid…
Lythenas Dec 28, 2023
d780540
Use correct space in fixTopBar
Lythenas Dec 30, 2023
a0263a1
Re-layout when workarea changes
Lythenas Dec 30, 2023
0ed9646
Merge remote-tracking branch 'upstream/develop' into fullscreen-avoid…
Lythenas Jan 12, 2024
7c7f2c9
Fix jumpyness when entering fullscreen
Lythenas Jan 13, 2024
9d8799b
Detect floating and scratch windows as fullscreen
Lythenas Jan 13, 2024
d67b64e
Merge remote-tracking branch 'upstream/develop' into fullscreen-avoid…
Lythenas Mar 30, 2024
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
55 changes: 55 additions & 0 deletions tiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ export function enable(extension) {
return false; // on return false destroys timeout
});
}

patchMonitorInFullscreen();
}

export function disable () {
Expand All @@ -205,6 +207,59 @@ export function disable () {
backgroundSettings = null;
interfaceSettings = null;
workspaceSettings = null;

unpatchMonitorInFullscreen();
}

// Patch monitor objects prototype to check our space for the inFullscreen
// property.
function patchMonitorInFullscreen() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lythenas, that this type of patching needs to be done in patches.js and using the patterns there, otherwise this wouldn't pass EGO review) - see examples there for patching prototypes (which will then be automatically reverted on PaperWM disable).

But in principal I can see what you've done here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good though - we can do that after.

@Lythenas Lythenas Nov 23, 2023

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know about the patches.js file. Will move it there.

But I think we can't use the pattern there, since monitor.prototype is undefined. Also I am not overwriting a normal function or property. I am setting a getter function for a property. And since that does not exist not sure how to restore it. I guess we would just safe the undefined.

Edit: I think the code in patches works directly on classes, right? So I don't think we can use it since monitor are just plain JS objects as far as I can tell.

The prototype seems to apply to all monitor objects but no other objects for some reason. I also don't know what happens when you plug in or unplag a monitor afterwards or change the monitor configuration. It is possible that the prototype will be lost when the objects change.

Maybe there is a better way to patch this but that is what I found works.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that fullscreen avoider does some interesting stuff for patching by calling toString on the function and string replacing some things: https://github.com/Noobsai/fullscreen-avoider/blob/master/src/extension.js#L91

@jtaala jtaala Nov 23, 2023

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, given what we're doing in this case, we can add it into Utils.js upgradeGnomeMonitors:

https://github.com/paperwm/PaperWM/blob/release/utils.js#L526-L536

This is nice since it's a dbus service hook that will get called whenever monitors change (e.g. if we add new monitors and remove monitors). We use this to upgrade monitor objects to add connector information (e.g. HDMI-1, eDP-1 etc.).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyway, can leave as is for the time being (since it's working fine) and can focus on the other issues (that you mentioned).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: I think the code in patches works directly on classes, right? So I don't think we can use it since monitor are just plain JS objects as far as I can tell.

No, Monitor is indeed a class - it's here:
https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/layout.js?ref_type=heads#L158-L171

You're essentially overriding the prototype class getter get inFullscreen().

Interestingly, Gnome haven't exported this so that's the main reason why we can't use it directly in patches. You're approach of getting a concrete implementation of one and overriding the prototype (which effects the Monitor class) will work though.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok. I thought is is not a class because it only shows up as an [object Object] in looking glass. But .constructor.name indeed returns Monitor.

const monitor1 = Main.layoutManager.monitors[0];
Object.defineProperties(
Object.getPrototypeOf(monitor1),
{
inFullscreen: {
// NOTE: Needs to be non-arrow function so `this` is bound
// correctly on call. This is necessary because we modify the
// prototype of multiple objects here.
get: function() {
// NOTE: This is wrapped in try-catch because an error here
// makes windows unclickable.
try {
// Find active space for monitor (this)
// NOTE: Indexing spaces.monitors[this] does not work
for (const [monitor, space] of spaces.monitors) {
if (monitor.index == this.index) {
return space.hasFullScreenWindow();
}
}
} catch (e) {
console.error(e);
}
// should not be reached, just here in case there is an
// error above
console.error(new Error(`Failed to find space for monitor`));
return false;
},
enumerable: true,
}
})
}

function unpatchMonitorInFullscreen() {
const monitor1 = Main.layoutManager.monitors[0];
// Reset value to false. This might be incorrect, but will be updated by
// gnome again after some time.
Object.defineProperties(
Object.getPrototypeOf(monitor1),
{
inFullscreen: {
value: false,
writable: true,
enumerable: true,
}
}
);
}

/**
Expand Down
16 changes: 7 additions & 9 deletions topbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,15 +731,13 @@ export function fixTopBar() {
let fullscreen = focusIsFloatOrScratch ? focused.fullscreen : selected && selected.fullscreen;

if (normal && !space.showTopBar) {
panelBox.scale_y = 0; // Update the workarea to support hide top bar
panelBox.hide();
}
else if (normal && fullscreen) {
panelBox.hide();
}
else {
panelBox.scale_y = 1;
panelBox.show();
// panelBox.scale_y = 0; // Update the workarea to support hide top bar
// panelBox.hide();
} else if (normal && fullscreen) {
// panelBox.hide();
} else {
// panelBox.scale_y = 1;
// panelBox.show();
}
}

Expand Down