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

Optionally set the max width for the appMenu and show the full title on hover (no matter the length). Choose appMenu's EllipsizeMode. #222

Merged
merged 2 commits into from
Feb 2, 2021
Merged
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
13 changes: 10 additions & 3 deletions unite@hardpixel.eu/convenience.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ var SettingsManager = GObject.registerClass(
'hide-app-menu-arrow': 'boolean',
'hide-app-menu-icon': 'boolean',
'reduce-panel-spacing': 'boolean',
'restrict-to-primary-screen': 'boolean'
'restrict-to-primary-screen': 'boolean',
'app-menu-max-width': 'int',
'app-menu-ellipsize-mode': 'enum'
}
}

Expand All @@ -50,8 +52,13 @@ var SettingsManager = GObject.registerClass(
getSetting(key) {
if (!this.exists(key)) return

let boolean = this.getSettingType(key) == 'boolean'
return boolean ? this.get_boolean(key) : this.get_string(key)
const settingsType = this.getSettingType(key)
if (settingsType === 'int')
return this.get_int(key)
else if (settingsType === 'boolean')
return this.get_boolean(key)
else
return this.get_string(key)
}
}
)
Expand Down
122 changes: 122 additions & 0 deletions unite@hardpixel.eu/panel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const Gi = imports._gi
const System = imports.system
const GObject = imports.gi.GObject
const GLib = imports.gi.GLib
const St = imports.gi.St
const Pango = imports.gi.Pango
const Clutter = imports.gi.Clutter
const Shell = imports.gi.Shell
const AppSystem = imports.gi.Shell.AppSystem.get_default()
Expand Down Expand Up @@ -551,6 +554,122 @@ var PanelDoubleClick = GObject.registerClass(
}
)

var AppMenuCustomizer = class AppMenuCustomizer extends PanelExtension {
constructor({ settings }) {
const active = val => val > 0
super(settings, 'app-menu-max-width', active)
}

_init() {
this.signals = new Handlers.Signals()
this.settings = new Handlers.Settings()

this.signals.connect(
AppMenu, 'notify::hover', this._onAppMenuHover.bind(this)
)

this.signals.connect(
AppMenu, 'button-press-event', this._onAppMenuClicked.bind(this)
)

this.settings.connect(
'app-menu-max-width', this._onMaxWidthChange.bind(this)
)

this.settings.connect(
'app-menu-ellipsize-mode', this._onEllipsizeModeChange.bind(this)
)

// tooltip label
this.tooltip = new St.Label({
visible: false,
style: 'background-color: #212121; \
border-radius: 6px; \
border: 1px solid dimgray; \
padding: 8px'
});
Main.uiGroup.add_child(this.tooltip)

this._onMaxWidthChange()
}

get appMenuMaxWidth() {
return this.settings.get('app-menu-max-width')
}

get ellipsizeMode() {
return this.settings.get('app-menu-ellipsize-mode')
}

_onAppMenuHover(appMenu) {
if (!appMenu._label)
return

this.isHovered = appMenu.get_hover()
if (!this.isHovered)
return this.tooltip.hide()

GLib.timeout_add(GLib.PRIORITY_DEFAULT, 400, () => {
if (this.isHovered && !this.tooltip.visible) {
const [mouseX, mouseY] = global.get_pointer()
this.tooltip.set_position(mouseX + 20, mouseY)
this.tooltip.set_text(appMenu._label.get_text())
this.tooltip.show()
}

return GLib.SOURCE_REMOVE
});
}

_onAppMenuClicked() {
this.isHovered = false
this.tooltip.hide()
}

_onMaxWidthChange() {
const label = AppMenu._label
if (!label)
return

const maxWidth = this.appMenuMaxWidth
label.set_style('max-width' + (maxWidth ? `: ${maxWidth}px` : ''))

this._onEllipsizeModeChange()
}

_onEllipsizeModeChange() {
const label = AppMenu._label
if (!label)
return

switch (this.ellipsizeMode) {
case "start":
label.get_clutter_text().set_ellipsize(Pango.EllipsizeMode.START)
break;

case "middle":
label.get_clutter_text().set_ellipsize(Pango.EllipsizeMode.MIDDLE)
break;

case "end":
label.get_clutter_text().set_ellipsize(Pango.EllipsizeMode.END)
}
}

_destroy() {
const label = AppMenu._label
if (label) {
label.get_clutter_text().set_ellipsize(Pango.EllipsizeMode.END)
label.set_style('max-width')
}

this.tooltip.destroy()

this.signals.disconnectAll()
this.settings.disconnectAll()
}
}

var PanelManager = GObject.registerClass(
class UnitePanelManager extends GObject.Object {
_init() {
Expand All @@ -561,6 +680,7 @@ var PanelManager = GObject.registerClass(
this.desktop = new DesktopName(this)
this.tray = new TrayIcons(this)
this.dblClick = new PanelDoubleClick()
this.appMCustom = new AppMenuCustomizer(this)
}

activate() {
Expand All @@ -570,6 +690,7 @@ var PanelManager = GObject.registerClass(
this.desktop.activate()
this.tray.activate()
this.dblClick.activate()
this.appMCustom.activate()
}

destroy() {
Expand All @@ -579,6 +700,7 @@ var PanelManager = GObject.registerClass(
this.desktop.destroy()
this.tray.destroy()
this.dblClick.destroy()
this.appMCustom.destroy()

this.settings.disconnectAll()
}
Expand Down
6 changes: 6 additions & 0 deletions unite@hardpixel.eu/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var PrefsWidget = GObject.registerClass(
this._bindSelects()
this._bindBooleans()
this._bindEnumerations()
this._bindInts()
}

_getWidget(name) {
Expand Down Expand Up @@ -67,6 +68,11 @@ var PrefsWidget = GObject.registerClass(
let settings = this._settings.getTypeSettings('enum')
settings.forEach(setting => { this._bindEnum(setting) })
}

_bindInts() {
let settings = this._settings.getTypeSettings('int')
settings.forEach(setting => { this._bindInput(setting, 'value') })
}
}
)

Expand Down
Binary file modified unite@hardpixel.eu/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<value value="2" nick="always" />
</enum>

<enum id="org.gnome.shell.extensions.unite.ellipsizeMode">
<value value="0" nick="start" />
<value value="1" nick="middle" />
<value value="2" nick="end" />
</enum>

<schema id="org.gnome.shell.extensions.unite" path="/org/gnome/shell/extensions/unite/">
<key name="use-system-fonts" type="b">
<default>true</default>
Expand Down Expand Up @@ -120,6 +126,16 @@
<summary>Hide app menu application icon.</summary>
</key>

<key name="app-menu-max-width" type="i">
<default>0</default>
<summary>Limit the width of the app menu. 0 means no limit.</summary>
</key>

<key name="app-menu-ellipsize-mode" enum="org.gnome.shell.extensions.unite.ellipsizeMode">
<default>"end"</default>
<summary>The place where characters will be omitted when the max width of the app menu is reached.</summary>
</key>

<key name="reduce-panel-spacing" type="b">
<default>true</default>
<summary>Reduce top bar items spacing.</summary>
Expand Down
Loading