Skip to content

Commit

Permalink
feat: add exception rules for skip taskbar
Browse files Browse the repository at this point in the history
Initial window exception for Conky, Guake and DDterm
  • Loading branch information
jmmaranan authored and mmstick committed Jul 8, 2021
1 parent 90b1ac7 commit b1b73f6
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 13 deletions.
4 changes: 2 additions & 2 deletions schemas/org.gnome.shell.extensions.pop-shell.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</key>

<key type="b" name="show-skip-taskbar">
<default>false</default>
<summary>Handle skip taskbar windows or windows with minimized to tray option</summary>
<default>true</default>
<summary>Handle minimized to tray windows</summary>
</key>

<!-- Tiling Options -->
Expand Down
55 changes: 52 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ interface Error {

type Result<T> = Ok<T> | Error;

export const DEFAULT_RULES: Array<FloatRule> = [
export const DEFAULT_FLOAT_RULES: Array<FloatRule> = [
{ class: "Floating Window Exceptions"},
{ class: "Authy Desktop", },
{ class: "Enpass", title: "Enpass Assistant" },
{ class: "Zotero", title: "Quick Format Citation" },
{ class: "Com.github.donadigo.eddy", },
{ class: "Conky", },
{ class: "Guake", },
{ class: "Com.github.amezin.ddterm", },
{ class: "gnome-screenshot", },
{ class: "jetbrains-toolbox", },
{ class: "jetbrains-webstorm", title: "License Activation" },
Expand All @@ -45,6 +47,22 @@ export const DEFAULT_RULES: Array<FloatRule> = [
{ class: "Gnome-initial-setup" },
];

export interface WindowRule {
class?: string;
title?: string;
disabled?: boolean;
}

/**
* These windows will skip showing in Overview, Thumbnails or SwitcherList
* And any rule here should be added on the DEFAULT_RULES above
*/
export const SKIPTASKBAR_EXCEPTIONS: Array<WindowRule> = [
{ class: "Conky", },
{ class: "Guake", },
{ class: "Com.github.amezin.ddterm", },
];

export interface FloatRule {
class?: string;
title?: string;
Expand All @@ -62,6 +80,12 @@ export class Config {
/** List of windows that should float, regardless of their WM hints */
float: Array<FloatRule> = [];

/**
* List of Windows with skip taskbar true but still hidden in Overview,
* Switchers, Workspace Thumbnails
*/
skiptaskbarhidden: Array<WindowRule> = [];

/** Logs window details on focus of window */
log_on_focus: boolean = false;

Expand Down Expand Up @@ -92,7 +116,7 @@ export class Config {
}

window_shall_float(wclass: string, title: string): boolean {
for (const rule of this.float.concat(DEFAULT_RULES)) {
for (const rule of this.float.concat(DEFAULT_FLOAT_RULES)) {
if (rule.class) {
if (!new RegExp(rule.class, 'i').test(wclass)) {
continue
Expand All @@ -111,6 +135,31 @@ export class Config {
return false;
}

skiptaskbar_shall_hide(meta_window: any) {
let wmclass = meta_window.get_wm_class();
let wmtitle = meta_window.get_title();

if (!meta_window.is_skip_taskbar()) return false;

for (const rule of this.skiptaskbarhidden.concat(SKIPTASKBAR_EXCEPTIONS)) {
if (rule.class) {
if (!new RegExp(rule.class, 'i').test(wmclass)) {
continue
}
}

if (rule.title) {
if (!new RegExp(rule.title, 'i').test(wmtitle)) {
continue
}
}

return rule.disabled ? false : true;
}

return false;
}

reload() {
const conf = Config.from_config();

Expand Down Expand Up @@ -141,7 +190,7 @@ export class Config {

toggle_system_exception(wmclass: string | undefined, wmtitle: string | undefined, disabled: boolean) {
if (disabled) {
for (const value of DEFAULT_RULES) {
for (const value of DEFAULT_FLOAT_RULES) {
if (value.class === wmclass && value.title === wmtitle) {
value.disabled = disabled;
this.float.push(value);
Expand Down
36 changes: 29 additions & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ export class Ext extends Ecs.System<ExtEvent> {
break;
case 'show-skip-taskbar':
if (this.settings.show_skiptaskbar()) {
_show_skip_taskbar_windows();
_show_skip_taskbar_windows(this);
} else {
_hide_skip_taskbar_windows();
}
Expand Down Expand Up @@ -2429,6 +2429,12 @@ function enable() {
});
}

if (ext.settings.show_skiptaskbar()) {
_show_skip_taskbar_windows(ext);
} else {
_hide_skip_taskbar_windows();
}

if (ext.was_locked) {
ext.was_locked = false;
return;
Expand Down Expand Up @@ -2478,6 +2484,8 @@ function disable() {
ext.auto_tiler.destroy(ext);
ext.auto_tiler = null;
}

_hide_skip_taskbar_windows();
}

if (indicator) {
Expand Down Expand Up @@ -2560,7 +2568,8 @@ let default_getcaption_workspace: any;
* need to added to config.ts as default floating
*
*/
function _show_skip_taskbar_windows() {
function _show_skip_taskbar_windows(ext: Ext) {
let cfg = ext.conf;
if (!GNOME_VERSION?.startsWith("40.")) {
// TODO GNOME 40 added a call to windowtracker and app var is not checked if null
// in WindowPreview._init(). Then new WindowPreview() is being called on
Expand All @@ -2572,7 +2581,8 @@ function _show_skip_taskbar_windows() {
Workspace.prototype._isOverviewWindow = function(window: any) {
// wm_class Gjs needs to be skipped to prevent the ghost window in
// workspace and overview
return (window.skip_taskbar && window.get_wm_class() !== "Gjs") ||
let show_skiptb = !cfg.skiptaskbar_shall_hide(window);
return (show_skiptb && window.skip_taskbar && window.get_wm_class() !== "Gjs") ||
default_isoverviewwindow_ws(window);
};
}
Expand Down Expand Up @@ -2610,7 +2620,8 @@ function _show_skip_taskbar_windows() {
let meta_win = win.get_meta_window();
// wm_class Gjs needs to be skipped to prevent the ghost window in
// workspace and overview
return (meta_win.skip_taskbar && meta_win.get_wm_class() !== "Gjs") ||
let show_skiptb = !cfg.skiptaskbar_shall_hide(meta_win);
return (show_skiptb && meta_win.skip_taskbar && meta_win.get_wm_class() !== "Gjs") ||
default_isoverviewwindow_ws_thumbnail(win);
};

Expand Down Expand Up @@ -2648,7 +2659,10 @@ function _show_skip_taskbar_windows() {
});

for (let i = 0; i < allRunningSkipTaskbarApps.length; i++) {
let appIcon = new AppIcon(windowTracker.get_window_app(allRunningSkipTaskbarApps[i]));
let meta_win = allRunningSkipTaskbarApps[i];
let show_skiptb = !cfg.skiptaskbar_shall_hide(meta_win);
if (meta_win.is_skip_taskbar() && !show_skiptb) continue;
let appIcon = new AppIcon(windowTracker.get_window_app(meta_win));
appIcon.cachedWindows = allWindows.filter(
w => windowTracker.get_window_app(w) === appIcon.app);
if (appIcon.cachedWindows.length > 0)
Expand All @@ -2675,8 +2689,16 @@ function _show_skip_taskbar_windows() {
let windows = global.display.get_tab_list(Meta.TabList.NORMAL_ALL,
workspace);
return windows.map(w => {
return w.is_attached_dialog() ? w.get_transient_for() : w;
}).filter((w, i, a) => w != null && a.indexOf(w) == i);
let show_skiptb = !cfg.skiptaskbar_shall_hide(w);
let meta_window = w.is_attached_dialog() ? w.get_transient_for() : w;
if (meta_window) {
if (!meta_window.is_skip_taskbar() ||
meta_window.is_skip_taskbar() && show_skiptb) {
return meta_window;
}
}
return null;
}).filter((w, i, a) => w != null && a.indexOf(w) == i);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function settings_dialog_view(): [AppWidgets, Gtk.Container] {
});

let show_skip_taskbar_label = new Gtk.Label({
label: "Show Skip Taskbar",
label: "Show Minimize to Tray Windows",
xalign: 0.0
});

Expand Down

0 comments on commit b1b73f6

Please sign in to comment.