From a309ef6099b4071baa7f5d98f3e9472fd906505d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Tue, 23 Feb 2021 11:56:02 +0100 Subject: [PATCH] Make remote app minimize, maximize and close buttons affect Clapper --- src/appRemote.js | 4 ++-- src/headerbar.js | 11 ++--------- src/headerbarBase.js | 9 +++++---- src/headerbarRemote.js | 20 ++++++++++++++++++++ src/player.js | 17 ++++++++++++++++- src/widgetRemote.js | 3 +-- 6 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 src/headerbarRemote.js diff --git a/src/appRemote.js b/src/appRemote.js index aa396e7f..7ce79724 100644 --- a/src/appRemote.js +++ b/src/appRemote.js @@ -1,6 +1,6 @@ const { GObject } = imports.gi; const { AppBase } = imports.src.appBase; -const { HeaderBarBase } = imports.src.headerbarBase; +const { HeaderBarRemote } = imports.src.headerbarRemote; const { WidgetRemote } = imports.src.widgetRemote; var AppRemote = GObject.registerClass( @@ -13,7 +13,7 @@ class ClapperAppRemote extends AppBase const clapperWidget = new WidgetRemote(); this.active_window.set_child(clapperWidget); - const headerBar = new HeaderBarBase(this.active_window); + const headerBar = new HeaderBarRemote(); this.active_window.set_titlebar(headerBar); this.active_window.maximize(); diff --git a/src/headerbar.js b/src/headerbar.js index 1635fc45..d04aab63 100644 --- a/src/headerbar.js +++ b/src/headerbar.js @@ -1,19 +1,12 @@ -const { GObject, Gtk } = imports.gi; +const { GObject } = imports.gi; const { HeaderBarBase } = imports.src.headerbarBase; var HeaderBar = GObject.registerClass( class ClapperHeaderBar extends HeaderBarBase { - _init() - { - super._init(); - this.add_css_class('osd'); - this.add_css_class('osdheaderbar'); - } - _onWindowButtonActivate(action) { - this.activate_action(action, null); + this.activate_action(`window.${action}`, null); } _onFloatButtonClicked() diff --git a/src/headerbarBase.js b/src/headerbarBase.js index 3bf511b7..24f45d8f 100644 --- a/src/headerbarBase.js +++ b/src/headerbarBase.js @@ -17,6 +17,8 @@ class ClapperHeaderBarBase extends Gtk.Box margin_start: 6, margin_end: 6, }); + this.add_css_class('osd'); + this.add_css_class('osdheaderbar'); this.isMaximized = false; this.isMenuOnLeft = true; @@ -197,12 +199,11 @@ class ClapperHeaderBarBase extends Gtk.Box }); button.add_css_class('circular'); - const action = (name === 'maximize') - ? 'window.toggle-maximized' - : 'window.' + name; + if(name === 'maximize') + name = 'toggle-maximized'; button.connect('clicked', - this._onWindowButtonActivate.bind(this, action) + this._onWindowButtonActivate.bind(this, name) ); return button; diff --git a/src/headerbarRemote.js b/src/headerbarRemote.js new file mode 100644 index 00000000..f8a8c9ae --- /dev/null +++ b/src/headerbarRemote.js @@ -0,0 +1,20 @@ +const { GObject } = imports.gi; +const { HeaderBarBase } = imports.src.headerbarBase; + +var HeaderBarRemote = GObject.registerClass( +class ClapperHeaderBarRemote extends HeaderBarBase +{ + _init() + { + super._init(); + this.extraButtonsBox.visible = false; + } + + _onWindowButtonActivate(action) + { + if(action === 'toggle-maximized') + action = 'toggle_maximized'; + + this.root.child.sendWs(action); + } +}); diff --git a/src/player.js b/src/player.js index f6b7f6f2..66856a81 100644 --- a/src/player.js +++ b/src/player.js @@ -252,8 +252,23 @@ class ClapperPlayer extends PlayerBase case 'set_playlist': this[action](value); break; + case 'toggle_maximized': + action = 'toggle-maximized'; + case 'minimize': + case 'close': + this.widget.activate_action(`window.${action}`, null); + break; default: - super.receiveWs(action, value); + const clapperWidget = this.widget.get_ancestor(Gtk.Grid); + + switch(action) { + case 'toggle_fullscreen': + clapperWidget.toggleFullscreen(); + break; + default: + super.receiveWs(action, value); + break; + } break; } } diff --git a/src/widgetRemote.js b/src/widgetRemote.js index 4ad3191e..a479a7c0 100644 --- a/src/widgetRemote.js +++ b/src/widgetRemote.js @@ -62,8 +62,7 @@ class ClapperWidgetRemote extends Gtk.Grid } break; case 'close': - const root = this.get_root(); - root.run_dispose(); + this.root.run_dispose(); break; default: break;