Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make menu applet resizable with mouse #11665

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 31 additions & 30 deletions files/usr/share/cinnamon/applets/[email protected]/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const AppUtils = require('./appUtils');

let appsys = Cinnamon.AppSystem.get_default();

const MAX_BUTTON_WIDTH = "max-width: 20em;";
const POPUP_MIN_WIDTH = 500;
const POPUP_MAX_WIDTH = 900;
const POPUP_MIN_HEIGHT = 400;
const POPUP_MAX_HEIGHT = 1400;

const RefreshFlags = Object.freeze({
APP: 0b000001,
Expand Down Expand Up @@ -177,7 +180,6 @@ class SimpleMenuItem {
this._signals = new SignalManager.SignalManager();

this.actor = new St.BoxLayout({ style_class: params.styleClass,
style: MAX_BUTTON_WIDTH,
reactive: params.reactive,
accessible_role: Atk.Role.MENU_ITEM });

Expand Down Expand Up @@ -1184,6 +1186,12 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
this._size_dirty = true;
});

this._resizer = new Applet.PopupResizeHandler(this.menu.actor,
() => this._orientation,
(w,h) => this._onBoxResized(w,h),
() => this.popup_width * global.ui_scale,
() => this.popup_height * global.ui_scale);

this.settings.bind("show-favorites", "showFavorites", () => this.queueRefresh(RefreshFlags.FAV_DOC));
this.settings.bind("show-places", "showPlaces", () => this.queueRefresh(RefreshFlags.PLACE));
this.settings.bind("show-recents", "showRecents", () => this.queueRefresh(RefreshFlags.RECENT));
Expand Down Expand Up @@ -1216,8 +1224,8 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
this.settings.bind("favbox-show", "favBoxShow", this._favboxtoggle);
this.settings.bind("fav-icon-size", "favIconSize", () => this.queueRefresh(RefreshFlags.FAV_APP | RefreshFlags.SYSTEM));
this.settings.bind("enable-animation", "enableAnimation", null);
this.settings.bind("restrict-menu-height", "restrictMenuHeight", null);
this.settings.bind("menu-height", "menuHeight", null);
this.settings.bind("popup-width", "popup_width");
this.settings.bind("popup-height", "popup_height");

this._updateKeybinding();

Expand Down Expand Up @@ -1294,6 +1302,19 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
})
}

_onBoxResized(width, height) {
width = (width / global.ui_scale).clamp(POPUP_MIN_WIDTH, POPUP_MAX_WIDTH);
height = (height / global.ui_scale).clamp(POPUP_MIN_HEIGHT, POPUP_MAX_HEIGHT);

//Only update settings when resizing is completed to avoid excessive disk writes.
if (!this._resizer.resizingInProgress) {
this.popup_width = width;
this.popup_height = height;
}

this._setMenuSize(width, height);
}

_updateKeybinding() {
Main.keybindingManager.addHotKey("overlay-key-" + this.instance_id, this.overlayKey, Lang.bind(this, function() {
if (!Main.overview.visible && !Main.expo.visible)
Expand Down Expand Up @@ -1406,26 +1427,16 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
});
}

_recalc_sizes() {
Util.each(this.applicationsBox.get_children(), c => c.hide());
_setMenuSize(width, height) {
this.main_container.natural_height = (height * global.ui_scale);
this.main_container.natural_width = (width * global.ui_scale);

this.main_container.natural_height = 0;
this.main_container.natural_height_set = false;
this.selectedAppBox.natural_width_set = false;
this.selectedAppBox.minimum_width_set = false;

if (this.restrictMenuHeight) {
this.main_container.natural_height = this.menuHeight * global.ui_scale;
} else {
this.main_container.natural_height = this.main_container.get_preferred_height(-1)[1];
}
this.menu.actor.set_width(width * global.ui_scale);
this.menu.actor.set_height(height * global.ui_scale);

this._update_scroll_policy(this.favoritesBox, this.favoritesScrollBox);
this._update_scroll_policy(this.categoriesBox, this.categoriesScrollBox);

this._resizeApplicationsBox();
this.selectedAppBox.width = this.selectedAppBox.width;

this._size_dirty = false;
}

Expand All @@ -1440,16 +1451,6 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
}
}

_resizeApplicationsBox() {
let width = -1;
Util.each(this.applicationsBox.get_children(), c => {
let [min, nat] = c.get_preferred_width(-1.0);
if (nat > width)
width = nat;
});
this.applicationsBox.set_width(width + 42); // The answer to life...
}

on_orientation_changed (orientation) {
this._updateIconAndLabel();
this._size_dirty = true;
Expand Down Expand Up @@ -1478,7 +1479,7 @@ class CinnamonMenuApplet extends Applet.TextIconApplet {
this.lastSelectedCategory = null;

if (this._size_dirty) {
this._recalc_sizes();
this._setMenuSize(this.popup_width, this.popup_height);
}

let n = Math.min(this._applicationsButtons.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"menu-layout" : {
"type" : "section",
"title" : "Layout and content",
"keys" : ["restrict-menu-height", "menu-height", "show-category-icons",
"keys" : ["show-category-icons",
"category-icon-size", "show-application-icons", "application-icon-size",
"favbox-show", "fav-icon-size", "show-places", "show-recents", "menu-editor-button"]
},
Expand Down Expand Up @@ -71,22 +71,6 @@
"tooltip" : "Enter custom text to show in the panel.",
"dependency" : "menu-custom"
},
"restrict-menu-height" : {
"type": "switch",
"default" : false,
"description" : "Use a fixed menu height",
"tooltip" : "Keep the size of the menu the same no matter how many favorites or categories there are."
},
"menu-height" : {
"type": "spinbutton",
"default" : 550,
"min" : 300,
"max" : 2000,
"step" : 10,
"units" : "px",
"description" : "Menu height",
"dependency" : "restrict-menu-height"
},
"show-category-icons" : {
"type" : "switch",
"default" : true,
Expand Down Expand Up @@ -205,5 +189,13 @@
"description" : "Open the menu editor",
"callback" : "_launch_editor",
"tooltip" : "Press this button to customize your menu entries."
},
"popup-width" : {
"type" : "generic",
"default" : 650
},
"popup-height" : {
"type" : "generic",
"default" : 650
}
}
Loading