Skip to content

Commit

Permalink
add option to control the top-most maximized window
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielfin authored and flexiondotorg committed May 29, 2019
1 parent 8c0ecc5 commit 77688c7
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 80 deletions.
31 changes: 31 additions & 0 deletions data/org.mate.window-applets.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<schemalist>
<schema id="org.mate.window-applets" path="/org/mate/window-applets/">
<child name="window-buttons" schema="org.mate.window-applets.window-buttons"/>
<child name="window-menu" schema="org.mate.window-applets.window-menu"/>
<child name="window-title" schema="org.mate.window-applets.window-title"/>
</schema>

<enum id="org.mate.window-applets.behaviours">
<value nick="active-always" value="1"/>
<value nick="active-maximized" value="2"/>
<value nick="topmost-maximized" value="3"/>
</enum>

<schema id="org.mate.window-applets.window-buttons" path="/org/mate/window-applets/window-buttons/">
<key name="use-marco-layout" type="b">
<default>true</default>
Expand Down Expand Up @@ -39,6 +47,29 @@
<summary>Whether the applet should control maximized windows only</summary>
</key>

<key name="behaviour" enum="org.mate.window-applets.behaviours">
<default>'active-always'</default>
<summary>Which window is controlled by the applet</summary>
</key>

</schema>

<schema id="org.mate.window-applets.window-title" path="/org/mate/window-applets/window-title/">

<key name="behaviour" enum="org.mate.window-applets.behaviours">
<default>'active-always'</default>
<summary>Which window is controlled by the applet</summary>
</key>

</schema>

<schema id="org.mate.window-applets.window-menu" path="/org/mate/window-applets/window-menu/">

<key name="behaviour" enum="org.mate.window-applets.behaviours">
<default>'active-always'</default>
<summary>Which window is controlled by the applet</summary>
</key>

</schema>

</schemalist>
48 changes: 26 additions & 22 deletions window-buttons-applet/dialog.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkAboutDialog" id="About">
Expand All @@ -13,6 +13,15 @@
<property name="website">https://github.com/ubuntu-mate/mate-window-applets</property>
<property name="logo_icon_name"/>
<property name="license_type">gpl-3-0</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">About</property>
<property name="has_subtitle">False</property>
<property name="show_close_button">True</property>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
Expand All @@ -28,15 +37,6 @@
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">About</property>
<property name="has_subtitle">False</property>
<property name="show_close_button">True</property>
</object>
</child>
</object>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">100</property>
Expand All @@ -53,6 +53,15 @@
<property name="events">GDK_STRUCTURE_MASK | GDK_SCROLL_MASK</property>
<property name="window_position">center</property>
<property name="gravity">static</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">Settings</property>
<property name="has_subtitle">False</property>
<property name="show_close_button">True</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
Expand Down Expand Up @@ -283,7 +292,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Control only maximized window :</property>
<property name="label" translatable="yes">Behaviour:</property>
</object>
<packing>
<property name="expand">True</property>
Expand All @@ -293,15 +302,19 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="control-maximized-window">
<object class="GtkComboBoxText" id="behaviour">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
<items>
<item id="active-always" translatable="yes">Always control active window</item>
<item id="active-maximized" translatable="yes">Only control active window when maximized</item>
<item id="topmost-maximized" translatable="yes">Control top-most maximized window</item>
</items>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">2</property>
<property name="position">1</property>
</packing>
</child>
Expand All @@ -314,14 +327,5 @@
</child>
</object>
</child>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">Settings</property>
<property name="has_subtitle">False</property>
<property name="show_close_button">True</property>
</object>
</child>
</object>
</interface>
56 changes: 38 additions & 18 deletions window-buttons-applet/window-buttons-applet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,21 @@ namespace WindowButtonsApplet{
}

public void reload(){
bool control_maximized_window = gsettings.get_boolean("control-maximized-window");

prev_window = window;

prev_window->actions_changed.disconnect(reload);
prev_window->state_changed.disconnect(reload);
Wnck.Screen.get_default().force_update();
window = Wnck.Screen.get_default().get_active_window();
if(prev_window != null){
prev_window->actions_changed.disconnect(reload);
prev_window->state_changed.disconnect(reload);
}

window = get_current_window();

if(window != null){
window->actions_changed.connect(reload);
window->state_changed.connect(reload);

if(control_maximized_window){
if(window->is_maximized())reload_actions(window);
else{
CLOSE.set_visible(false);
MINIMIZE.set_visible(false);
MAXIMIZE.set_visible(false);
}
}
else{
reload_actions(window);
}
reload_actions(window);
}
else {
CLOSE.set_visible(false);
Expand Down Expand Up @@ -205,6 +196,35 @@ namespace WindowButtonsApplet{
this.set_spacing(spacing);
}

private Wnck.Window get_current_window(){
Wnck.Window* win = null;
string behaviour = gsettings.get_string("behaviour");

Wnck.Screen.get_default().force_update();

switch(behaviour){
case "active-always":
win = Wnck.Screen.get_default().get_active_window();
break;
case "active-maximized":
win = Wnck.Screen.get_default().get_active_window();
if(!win->is_maximized())
win = null;
break;
case "topmost-maximized":
List<Wnck.Window*> windows = Wnck.Screen.get_default().get_windows_stacked().copy();
windows.reverse();
foreach(Wnck.Window* w in windows) {
if(w->is_maximized()){
win = w;
break;
}
}
break;
}

return win;
}
}

private bool factory(MatePanel.Applet applet,string iid){
Expand Down Expand Up @@ -249,14 +269,14 @@ namespace WindowButtonsApplet{
widget_container.gsettings.bind("theme",builder.get_object("theme"),"text",SettingsBindFlags.DEFAULT);
widget_container.gsettings.bind("spacing",builder.get_object("spacing"),"value",SettingsBindFlags.DEFAULT);
widget_container.gsettings.bind("padding",builder.get_object("padding"),"value",SettingsBindFlags.DEFAULT);
widget_container.gsettings.bind("control-maximized-window",builder.get_object("control-maximized-window"),"state",SettingsBindFlags.DEFAULT);
widget_container.gsettings.bind("behaviour",builder.get_object("behaviour"),"active_id",SettingsBindFlags.DEFAULT);

widget_container.gsettings.changed["use-marco-layout"].connect(widget_container.change_layout);
widget_container.gsettings.changed["buttons-layout"].connect(widget_container.change_layout);
widget_container.gsettings.changed["theme"].connect(widget_container.change_theme);
widget_container.gsettings.changed["spacing"].connect( (key) => { widget_container.change_size(applet.get_size()); } );
widget_container.gsettings.changed["padding"].connect( (key) => { widget_container.change_size(applet.get_size()); } );
widget_container.gsettings.changed["control-maximized-window"].connect( (key) => { widget_container.reload(); } );
widget_container.gsettings.changed["behaviour"].connect( (key) => { widget_container.reload(); } );
applet.setup_menu(menu,action_group);

settings.delete_event.connect( (event) => { settings.hide() ; return true ; } );
Expand Down
70 changes: 68 additions & 2 deletions window-menu-applet/dialog.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkAboutDialog" id="About">
Expand All @@ -13,6 +13,15 @@
<property name="website">https://github.com/ubuntu-mate/mate-window-applets</property>
<property name="logo_icon_name"/>
<property name="license_type">gpl-3-0</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">About</property>
<property name="has_subtitle">False</property>
<property name="show_close_button">True</property>
</object>
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
Expand All @@ -28,14 +37,71 @@
</child>
</object>
</child>
</object>
<object class="GtkWindow" id="Settings">
<property name="can_focus">False</property>
<property name="events">GDK_STRUCTURE_MASK | GDK_SCROLL_MASK</property>
<property name="window_position">center</property>
<property name="gravity">static</property>
<child type="titlebar">
<object class="GtkHeaderBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title">About</property>
<property name="title">Settings</property>
<property name="has_subtitle">False</property>
<property name="show_close_button">True</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Behaviour:</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">2</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="behaviour">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">center</property>
<items>
<item id="active-always" translatable="yes">Always control active window</item>
<item id="active-maximized" translatable="yes">Only control active window when maximized</item>
<item id="topmost-maximized" translatable="yes">Control top-most maximized window</item>
</items>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
Loading

0 comments on commit 77688c7

Please sign in to comment.