summaryrefslogtreecommitdiffstats
path: root/extensions/vertical-workspaces/panel.js
blob: 2f7143d621811a943410e280fd2165d5b4531118 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
 * Vertical Workspaces
 * panel.js
 * 
 * @author     GdH <G-dH@github.com>
 * @copyright  2022 - 2023
 * @license    GPL-3.0
 *
 */

'use strict';

const Main = imports.ui.main;
const Me = imports.misc.extensionUtils.getCurrentExtension();

const ANIMATION_TIME = imports.ui.overview.ANIMATION_TIME;

let opt;
let _showingOverviewConId;
let _hidingOverviewConId;
let _styleChangedConId;

function update(reset = false) {
    opt = Me.imports.settings.opt;
    const panelBox = Main.layoutManager.panelBox;
    const panelHeight = Main.panel.height; // panelBox height can be 0 after shell start

    const geometry = global.display.get_monitor_geometry(global.display.get_primary_monitor());
    if (reset || opt.PANEL_POSITION_TOP) {
        panelBox.set_position(geometry.x, geometry.y);
    } else {
        panelBox.set_position(geometry.x, geometry.y + geometry.height - panelHeight);
    }

    if (!_styleChangedConId) {
        Main.panel.connect('style-changed', ()=> Main.panel.remove_style_pseudo_class('overview'));
    }

    if (reset || opt.PANEL_MODE === 0) {
        //_disconnectPanel();
        _disconnectOverview()
        _reparentPanel(false);
        _showPanel();

        if (_styleChangedConId) {
            Main.panel.disconnect(_styleChangedConId);
            _styleChangedConId = 0;
        }

        panelBox.translation_y = 0;
        panelBox.opacity = 255;
    } else if (opt.PANEL_MODE === 1) {
        if (opt.SHOW_WS_PREVIEW_BG) {
            _reparentPanel(true);
            if (opt.OVERVIEW_MODE2) {
                // in OM2 if the panel has been moved to the overviewGroup move panel above all
                Main.layoutManager.overviewGroup.set_child_above_sibling(panelBox, null);
            } else {
                // otherwise move the panel below overviewGroup so it can get below workspacesDisplay
                Main.layoutManager.overviewGroup.set_child_below_sibling(panelBox, Main.overview._overview);
            }
            _showPanel(true);
        } else {
            // if ws preview bg is disabled, panel can stay in uiGroup
            _reparentPanel(false);
            _showPanel(false);
            if (!_hidingOverviewConId)
                _hidingOverviewConId = Main.overview.connect('hiding', () => {
                    if ((!opt.SHOW_WS_PREVIEW_BG || opt.OVERVIEW_MODE2)) {
                        _showPanel(false);
                    }
            });
            if (!_showingOverviewConId)
                _showingOverviewConId = Main.overview.connect('showing', () => {
                    if ((!opt.SHOW_WS_PREVIEW_BG || opt.OVERVIEW_MODE2)) {
                        _showPanel(true);
                    }
            });
        }

        _connectPanel();
    } else if (opt.PANEL_MODE === 2) {
        _disconnectOverview();
        _reparentPanel(false);
        _showPanel(false);
        _connectPanel();
    }
    _setPanelStructs(reset || opt.PANEL_MODE === 0);
}

function _disconnectOverview() {
    if (_hidingOverviewConId) {
        Main.overview.disconnect(_hidingOverviewConId);
        _hidingOverviewConId = 0;
    }
    if (_showingOverviewConId) {
        Main.overview.disconnect(_showingOverviewConId);
        _showingOverviewConId = 0;
    }
}

function _reparentPanel(reparent = false) {
    const panel = Main.layoutManager.panelBox;
    if (reparent && panel.get_parent() === Main.layoutManager.uiGroup) {
        Main.layoutManager.uiGroup.remove_child(panel);
        Main.layoutManager.overviewGroup.add_child(panel);
    } else if (!reparent && panel.get_parent() === Main.layoutManager.overviewGroup) {
        Main.layoutManager.overviewGroup.remove_child(panel);
        // return the panel at default position, pane shouldn't cover objects that should be above
        Main.layoutManager.uiGroup.insert_child_at_index(panel, 4);
    }
}

function _setPanelStructs(state) {
    Main.layoutManager._trackedActors.forEach(a => {
        if (a.actor === Main.layoutManager.panelBox)
            a.affectsStruts = state;
    });

    // workaround to force maximized windows to resize after removing affectsStruts
    // simulation of minimal swipe gesture to the opposite direction
    // todo - needs better solution!!!!!!!!!!!
    /*const direction = _getAppGridAnimationDirection() === 2 ? 1 : -1;
    Main.overview._swipeTracker._beginTouchSwipe(null, global.get_current_time(), 1, 1);
    Main.overview._swipeTracker._updateGesture(null, global.get_current_time(), direction, 1);
    GLib.timeout_add(0, 50, () => Main.overview._swipeTracker._endGesture(global.get_current_time(), 1, true));*/
}

function _showPanel(show = true) {
    if (show) {
        Main.panel.opacity = 255;
        Main.layoutManager.panelBox.ease({
            duration: ANIMATION_TIME,
            translation_y: 0,
            onComplete: () => {
                _setPanelStructs(opt.PANEL_MODE === 0);
            }
        });

    } else {
        const panelHeight = Main.panel.height;
        Main.layoutManager.panelBox.ease({
            duration: ANIMATION_TIME,
            translation_y: opt.PANEL_POSITION_TOP ? -panelHeight + 1 : panelHeight - 1,
            onComplete: () => {
                Main.panel.opacity = 0;
                _setPanelStructs(opt.PANEL_MODE === 0);
            }
        });
    }
}

function _connectPanel() {
    // not reliable, disabled for now
    /*if (!_panelEnterSigId) {
        _panelEnterSigId = Main.panel.connect('enter-event', () => {
            if (!Main.overview._shown)
                _showPanel(true);
        });
    }
    if (!_panelLeaveSigId) {
        _panelLeaveSigId = Main.panel.connect('leave-event', () => {
            if (!Main.overview._shown)
                _showPanel(false);
        });
    }*/
}

function _disconnectPanel() {
    /*if (_panelEnterSigId) {
        Main.panel.disconnect(_panelEnterSigId);
        _panelEnterSigId = 0;
    }
    if (_panelLeaveSigId) {
        Main.panel.disconnect(_panelLeaveSigId);
        _panelLeaveSigId = 0;
    }*/
}