fthx / dock-from-dash

GNU General Public License v3.0
97 stars 20 forks source link

[Request] intelligence hide option #75

Closed ghabit closed 1 year ago

ghabit commented 1 year ago

Thank you for your work! I'd like to extension work with it like a full functionality dock - is it possible to make intelligence hide option? Show the dock when it doesn't obstruct focused application windows. And we can call it by pressure when it is hidden (mentioned here https://github.com/fthx/dock-from-dash/issues/58) I think it will be enough to migrate from any others dash extensions, minimalistic yet functional.

fthx commented 1 year ago

When I looked at this, that was quite a lot of work though...

fthx commented 1 year ago

https://github.com/micheleg/dash-to-dock/blob/ubuntu-dock/intellihide.js

is as long as the entire extension.js code here ;-)

ghabit commented 1 year ago

Dash to dock have many other options there, I think wise deduction is to take only needed parts. However, I’m not able to code at all, but just started python tutorial. :)

fthx commented 1 year ago

I do not see options in this file.

dgsasha commented 1 year ago

I actually started working on this today and i've made a good bit of progress. I'll share more tomorrow when I'm less tired but so far I've gotten the dock to hide when windows pass over it (still needs work though) and I've gotten the dock to hide when windows are maximized. I used a lot of code from dash to dock but i'm also trying to make it as simple as possible because dash to dock is a really complex extension.

dgsasha commented 1 year ago

Dash to dock have many other options there, I think wise deduction is to take only needed parts. However, I’m not able to code at all, but just started python tutorial. :)

This is off topic, but I hope you have fun learning how to code :)

ghabit commented 1 year ago

i'm also trying to make it as simple as possible

I believe this is perfect approach. Thank you for your work!

fthx commented 1 year ago

The key function is here. We have to keep it simple: hide if focused window does overlap the dock.

_doCheckOverlap() {

    if (!this._isEnabled || (this._targetBox == null))
        return;

    let overlaps = OverlapStatus.FALSE;
    let windows = global.get_window_actors();

    if (windows.length > 0) {
        /*
         * Get the top window on the monitor where the dock is placed.
         * The idea is that we dont want to overlap with the windows of the topmost application,
         * event is it's not the focused app -- for instance because in multimonitor the user
         * select a window in the secondary monitor.
         */

        let topWindow = null;
        for (let i = windows.length - 1; i >= 0; i--) {
            let meta_win = windows[i].get_meta_window();
            if (this._handledWindow(windows[i]) && (meta_win.get_monitor() == this._monitorIndex)) {
                topWindow = meta_win;
                break;
            }
        }

        if (topWindow !== null) {
            this._topApp = this._tracker.get_window_app(topWindow);
            // If there isn't a focused app, use that of the window on top
            this._focusApp = this._tracker.focus_app || this._topApp

            windows = windows.filter(this._intellihideFilterInteresting, this);

            for (let i = 0;  i < windows.length; i++) {
                let win = windows[i].get_meta_window();

                if (win) {
                    let rect = win.get_frame_rect();

                    let test = (rect.x < this._targetBox.x2) &&
                               (rect.x + rect.width > this._targetBox.x1) &&
                               (rect.y < this._targetBox.y2) &&
                               (rect.y + rect.height > this._targetBox.y1);

                    if (test) {
                        overlaps = OverlapStatus.TRUE;
                        break;
                    }
                }
            }
        }
    }

    if (this._status !== overlaps) {
        this._status = overlaps;
        this.emit('status-changed', this._status);
    }

}
ghabit commented 1 year ago

How to implement this for testing?

fthx commented 1 year ago

That's Ubuntu Dock function. Needs some work inside Dock from dash.

fthx commented 1 year ago

Unfortunately GJS doc is down since some weeks: https://gjs-docs.gnome.org/meta11~11_api/ so I cannot work on this atm.

dgsasha commented 1 year ago

@fthx don't worry about it, I already got it working.

Here's a demo of what I have

I still need to clean up the code and make sure it's not negatively impacting performance, but it works pretty well.

dgsasha commented 1 year ago

@fthx There is a problem with this though, Dash to Dock is licensed under the GPL v2 license. Since I used code from Dash to Dock, I believe you would have to change the license of your extension to the GPL v2 license to include the code. Let me know what your thoughts on this are.

ghabit commented 1 year ago

@fthx don't worry about it, I already got it working. Screencast.from.2023-01-07.18-03-18.webm

I still need to clean up the code and make sure it's not negatively impacting performance, but it works pretty well.

It looks amazing!

dgsasha commented 1 year ago

@fthx I apologize for mentioning you, but can I have your permission to change the license in my fork of this repo to GPLv2 so I can share the code on GitHub?

fthx commented 1 year ago

there's no problem image keep v3 here

dgsasha commented 1 year ago

Oh thank you for letting me know, didn't notice that. I will open a pull request when I get home.

ghabit commented 1 year ago

I see some commits, is it possible to install version with this functionality?

fthx commented 1 year ago

Soon. ATM I have a lot of work, should be much better in 2 weeks.

pchmykh commented 1 year ago

Do we have some way to enable this option for now?

fthx commented 1 year ago

I have to include this code in the new version. For now I do not have the time, I will be back in extensions around mid-november, except for bugs.

fthx commented 1 year ago

That's a heavy part of code. So I won't include that, let's keep it simple and bug free.