From 78d74a34d67d9b1321ed2668b724659165f04b5f Mon Sep 17 00:00:00 2001 From: Rick Calixte <10281587+rcalixte@users.noreply.github.com> Date: Tue, 9 Aug 2022 03:08:10 -0400 Subject: [PATCH] Improve backward compatibility to 4.2 and fix remaining 5.4 bugs (#4410) --- .../{5.2 => 4.2}/BarIndicatorStyle.js | 64 +++++++++---------- .../{5.2 => 4.2}/GridStyle.js | 44 ++++++------- .../{5.2 => 4.2}/WorkspaceController.js | 10 +-- .../{5.2 => 4.2}/applet.js | 0 .../{5.2 => 4.2}/settings-schema.json | 0 .../5.4/BarIndicatorStyle.js | 64 +++++++++---------- .../workspace-grid@hernejj/5.4/GridStyle.js | 44 ++++++------- .../5.4/WorkspaceController.js | 10 +-- .../workspace-grid@hernejj/5.4/applet.js | 16 ++--- 9 files changed, 126 insertions(+), 126 deletions(-) rename workspace-grid@hernejj/files/workspace-grid@hernejj/{5.2 => 4.2}/BarIndicatorStyle.js (95%) rename workspace-grid@hernejj/files/workspace-grid@hernejj/{5.2 => 4.2}/GridStyle.js (93%) rename workspace-grid@hernejj/files/workspace-grid@hernejj/{5.2 => 4.2}/WorkspaceController.js (98%) rename workspace-grid@hernejj/files/workspace-grid@hernejj/{5.2 => 4.2}/applet.js (100%) rename workspace-grid@hernejj/files/workspace-grid@hernejj/{5.2 => 4.2}/settings-schema.json (100%) diff --git a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.2/BarIndicatorStyle.js b/workspace-grid@hernejj/files/workspace-grid@hernejj/4.2/BarIndicatorStyle.js similarity index 95% rename from workspace-grid@hernejj/files/workspace-grid@hernejj/5.2/BarIndicatorStyle.js rename to workspace-grid@hernejj/files/workspace-grid@hernejj/4.2/BarIndicatorStyle.js index 4e3836f73be..3c021a5066f 100644 --- a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.2/BarIndicatorStyle.js +++ b/workspace-grid@hernejj/files/workspace-grid@hernejj/4.2/BarIndicatorStyle.js @@ -7,7 +7,7 @@ function BarIndicatorStyle(applet, cols, rows, height) { } BarIndicatorStyle.prototype = { - + _init: function(applet, cols, rows, height) { this.applet = applet; this.button = []; @@ -15,43 +15,43 @@ BarIndicatorStyle.prototype = { this.switch_id = global.window_manager.connect('switch-workspace', Lang.bind(this, this.update)); this.scroll_id = this.applet.actor.connect('scroll-event', Lang.bind(this,this.onMouseScroll)); }, - + update_grid: function(cols, rows, height) { this.cols = cols; this.rows = rows; this.height = height; this.rebuild(); }, - + cleanup: function() { global.window_manager.disconnect(this.switch_id); this.applet.actor.disconnect(this.scroll_id); }, - + onMouseScroll: function(actor, event){ if (this.scrollby == 'row') this.scrollByRow(event); else this.scrollByCol(event); }, - + scrollByCol: function(event) { var idx = global.screen.get_active_workspace_index(); - - if (event.get_scroll_direction() == 0) idx--; + + if (event.get_scroll_direction() == 0) idx--; else if (event.get_scroll_direction() == 1) idx++; - + if(global.screen.get_workspace_by_index(idx) != null) global.screen.get_workspace_by_index(idx).activate(global.get_current_time()); }, - + scrollByRow: function(event) { var idx = global.screen.get_active_workspace_index(); var numworkspaces = this.rows * this.cols; - + var row = Math.floor(idx/this.cols); var col = idx % this.cols; - + if (event.get_scroll_direction() == 0) { row--; if (row < 0) { @@ -66,19 +66,19 @@ BarIndicatorStyle.prototype = { col++; } } - + if (col < 0 || col >= this.cols) return; - + idx = row*this.cols + col; - + if(global.screen.get_workspace_by_index(idx) != null) global.screen.get_workspace_by_index(idx).activate(global.get_current_time()); }, onRowIndicatorClicked: function(actor, event) { if (event.get_button() != 1) return false; - + let curws_idx = global.screen.get_active_workspace_index(); let curws_row = Math.floor(curws_idx/this.cols); let [x, y] = event.get_coords(); @@ -89,7 +89,7 @@ BarIndicatorStyle.prototype = { let clicked_row = Math.floor(this.rows*y/h); clicked_idx = (clicked_row * this.cols) + (curws_idx % this.cols); - global.screen.get_workspace_by_index(clicked_idx).activate(global.get_current_time()); + global.screen.get_workspace_by_index(clicked_idx).activate(global.get_current_time()); return true; }, @@ -97,12 +97,12 @@ BarIndicatorStyle.prototype = { if (event.get_button() != 1) return false; global.screen.get_workspace_by_index(actor.index).activate(global.get_current_time()); }, - + setReactivity: function(reactive) { for (let i=0; i < this.button.length; ++i) this.button[i].set_reactive(reactive); - }, - + }, + rebuild: function() { this.applet.actor.destroy_all_children(); @@ -117,7 +117,7 @@ BarIndicatorStyle.prototype = { this.button = []; for ( let i=0; i= low && i < high) this.button[i].show(); else this.button[i].hide(); - + if (i == active_ws) { this.button[i].get_child().set_text((i+1).toString()); this.button[i].add_style_pseudo_class('outlined'); @@ -159,21 +159,21 @@ BarIndicatorStyle.prototype = { this.button[i].remove_style_pseudo_class('outlined'); } } - + if ( this.row_indicator ) { this.row_indicator.queue_repaint(); } }, - + draw_row_indicator: function(area) { let [width, height] = area.get_surface_size(); let themeNode = this.row_indicator.get_theme_node(); let cr = area.get_context(); - + let base_color = this.get_base_color(); let active_color = null; let inactive_color = null; - + if (this.is_theme_light_on_dark()) { active_color = base_color.lighten(); inactive_color = base_color.darken(); @@ -182,10 +182,10 @@ BarIndicatorStyle.prototype = { active_color = base_color.darken().darken(); inactive_color = base_color.lighten().lighten(); } - + let active = global.screen.get_active_workspace_index(); let active_row = Math.floor(active/this.cols); - + // Catch overflow due to externally added/removed workspaces if (active >= this.button.length) active_row = (this.button.length-1) /this.cols; @@ -200,12 +200,12 @@ BarIndicatorStyle.prototype = { cr.stroke(); } }, - + is_theme_light_on_dark: function() { let selected_idx = global.screen.get_active_workspace_index(); let unselected_idx = 0; if (unselected_idx == selected_idx) unselected_idx = 1; - + let selected_txt_color = this.button[selected_idx].get_theme_node().get_color('color'); let unselected_txt_color = this.button[unselected_idx].get_theme_node().get_color('color'); @@ -213,7 +213,7 @@ BarIndicatorStyle.prototype = { let unsel_avg = (unselected_txt_color.red + unselected_txt_color.green + unselected_txt_color.blue)/3; return (sel_avg < unsel_avg); }, - + // All colors we use in this applet are based on this theme defined color. // We simply grab the color of a normal, non-outlined workspae button. get_base_color: function() { diff --git a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.2/GridStyle.js b/workspace-grid@hernejj/files/workspace-grid@hernejj/4.2/GridStyle.js similarity index 93% rename from workspace-grid@hernejj/files/workspace-grid@hernejj/5.2/GridStyle.js rename to workspace-grid@hernejj/files/workspace-grid@hernejj/4.2/GridStyle.js index 9a2b7f18752..95c2d2f5fa3 100644 --- a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.2/GridStyle.js +++ b/workspace-grid@hernejj/files/workspace-grid@hernejj/4.2/GridStyle.js @@ -7,7 +7,7 @@ function GridStyle(applet, cols, rows, height) { } GridStyle.prototype = { - + _init: function(applet, cols, rows, height) { this.scrollby = 'col'; this.applet = applet; @@ -17,43 +17,43 @@ GridStyle.prototype = { this.switch_id = global.window_manager.connect('switch-workspace', Lang.bind(this, this.update)); this.scroll_id = this.applet.actor.connect('scroll-event', Lang.bind(this,this.onMouseScroll)); }, - + cleanup: function() { global.window_manager.disconnect(this.switch_id); this.applet.actor.disconnect(this.scroll_id); }, - + update_grid: function(cols, rows, height) { this.cols = cols; this.rows = rows; this.height = height; this.rebuild(); }, - + onMouseScroll: function(actor, event){ if (this.scrollby == 'row') this.scrollByRow(event); else this.scrollByCol(event); }, - + scrollByCol: function(event) { var idx = global.screen.get_active_workspace_index(); - - if (event.get_scroll_direction() == 0) idx--; + + if (event.get_scroll_direction() == 0) idx--; else if (event.get_scroll_direction() == 1) idx++; - + if(global.screen.get_workspace_by_index(idx) != null) global.screen.get_workspace_by_index(idx).activate(global.get_current_time()); }, - + scrollByRow: function(event) { var idx = global.screen.get_active_workspace_index(); var numworkspaces = this.rows * this.cols; - + var row = Math.floor(idx/this.cols); var col = idx % this.cols ; - + if (event.get_scroll_direction() == 0) { row--; if (row < 0) { @@ -68,12 +68,12 @@ GridStyle.prototype = { col++; } } - + if (col < 0 || col >= this.cols) return; - + idx = row*this.cols + col; - + if(global.screen.get_workspace_by_index(idx) != null) global.screen.get_workspace_by_index(idx).activate(global.get_current_time()); }, @@ -82,23 +82,23 @@ GridStyle.prototype = { if (event.get_button() != 1) return false; global.screen.get_workspace_by_index(actor.index).activate(global.get_current_time()); }, - + setReactivity: function(reactive) { for (let i=0; i < this.button.length; ++i) - this.button[i].reactive = reactive; - }, - + this.button[i].reactive = reactive; + }, + rebuild: function() { this.applet.actor.destroy_all_children(); this.table = new St.Table({homogeneous: false, reactive: true }); this.applet.actor.add(this.table); - + let btn_height = this.height/this.rows; this.button = []; for(let r=0; r < this.rows; r++) { for(let c=0; c < this.cols; c++) { let i = (r*this.cols)+c; - + this.button[i] = new St.Button({ name: 'workspaceButton', style_class: 'workspace-button', reactive: true }); this.button[i].index = i; this.button[i].set_height(btn_height); @@ -112,13 +112,13 @@ GridStyle.prototype = { update: function() { let active_ws = global.screen.get_active_workspace_index(); - + for (let i=0; i < this.button.length; ++i) { if (i == active_ws) this.button[i].add_style_pseudo_class('outlined'); else this.button[i].remove_style_pseudo_class('outlined'); } - } + } }; diff --git a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.2/WorkspaceController.js b/workspace-grid@hernejj/files/workspace-grid@hernejj/4.2/WorkspaceController.js similarity index 98% rename from workspace-grid@hernejj/files/workspace-grid@hernejj/5.2/WorkspaceController.js rename to workspace-grid@hernejj/files/workspace-grid@hernejj/4.2/WorkspaceController.js index dac075f43eb..4af707c8d6c 100644 --- a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.2/WorkspaceController.js +++ b/workspace-grid@hernejj/files/workspace-grid@hernejj/4.2/WorkspaceController.js @@ -6,11 +6,11 @@ function WorkspaceController(cols, rows) { } WorkspaceController.prototype = { - + _init: function(cols, rows) { this.set_workspace_grid(cols, rows); }, - + // Create proper workspace layout geometry within Gnome set_workspace_grid: function (cols, rows) { this.cols = cols; @@ -18,12 +18,12 @@ WorkspaceController.prototype = { this.__equalize_num_workspaces(); global.screen.override_workspace_layout(Meta.ScreenCorner.TOPLEFT, false, rows, cols); }, - + // Update Gnome's view of workspaces to reflect our count based on row*col. __equalize_num_workspaces: function() { let new_ws_count = this.cols * this.rows; let old_ws_count = global.screen.n_workspaces; - + if (new_ws_count > old_ws_count) { for (let i=old_ws_count; i= this.cols) return; - + idx = row*this.cols + col; - + if(global.screen.get_workspace_by_index(idx) != null) global.screen.get_workspace_by_index(idx).activate(global.get_current_time()); }, onRowIndicatorClicked: function(actor, event) { if (event.get_button() != 1) return false; - + let curws_idx = global.screen.get_active_workspace_index(); let curws_row = Math.floor(curws_idx/this.cols); let [x, y] = event.get_coords(); @@ -89,7 +89,7 @@ BarIndicatorStyle.prototype = { let clicked_row = Math.floor(this.rows*y/h); clicked_idx = (clicked_row * this.cols) + (curws_idx % this.cols); - global.screen.get_workspace_by_index(clicked_idx).activate(global.get_current_time()); + global.screen.get_workspace_by_index(clicked_idx).activate(global.get_current_time()); return true; }, @@ -97,12 +97,12 @@ BarIndicatorStyle.prototype = { if (event.get_button() != 1) return false; global.screen.get_workspace_by_index(actor.index).activate(global.get_current_time()); }, - + setReactivity: function(reactive) { for (let i=0; i < this.button.length; ++i) this.button[i].set_reactive(reactive); - }, - + }, + rebuild: function() { this.applet.actor.destroy_all_children(); @@ -117,7 +117,7 @@ BarIndicatorStyle.prototype = { this.button = []; for ( let i=0; i= low && i < high) this.button[i].show(); else this.button[i].hide(); - + if (i == active_ws) { this.button[i].get_child().set_text((i+1).toString()); this.button[i].add_style_pseudo_class('outlined'); @@ -159,21 +159,21 @@ BarIndicatorStyle.prototype = { this.button[i].remove_style_pseudo_class('outlined'); } } - + if ( this.row_indicator ) { this.row_indicator.queue_repaint(); } }, - + draw_row_indicator: function(area) { let [width, height] = area.get_surface_size(); let themeNode = this.row_indicator.get_theme_node(); let cr = area.get_context(); - + let base_color = this.get_base_color(); let active_color = null; let inactive_color = null; - + if (this.is_theme_light_on_dark()) { active_color = base_color.lighten(); inactive_color = base_color.darken(); @@ -182,10 +182,10 @@ BarIndicatorStyle.prototype = { active_color = base_color.darken().darken(); inactive_color = base_color.lighten().lighten(); } - + let active = global.screen.get_active_workspace_index(); let active_row = Math.floor(active/this.cols); - + // Catch overflow due to externally added/removed workspaces if (active >= this.button.length) active_row = (this.button.length-1) /this.cols; @@ -200,12 +200,12 @@ BarIndicatorStyle.prototype = { cr.stroke(); } }, - + is_theme_light_on_dark: function() { let selected_idx = global.screen.get_active_workspace_index(); let unselected_idx = 0; if (unselected_idx == selected_idx) unselected_idx = 1; - + let selected_txt_color = this.button[selected_idx].get_theme_node().get_color('color'); let unselected_txt_color = this.button[unselected_idx].get_theme_node().get_color('color'); @@ -213,7 +213,7 @@ BarIndicatorStyle.prototype = { let unsel_avg = (unselected_txt_color.red + unselected_txt_color.green + unselected_txt_color.blue)/3; return (sel_avg < unsel_avg); }, - + // All colors we use in this applet are based on this theme defined color. // We simply grab the color of a normal, non-outlined workspae button. get_base_color: function() { diff --git a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.4/GridStyle.js b/workspace-grid@hernejj/files/workspace-grid@hernejj/5.4/GridStyle.js index 9a2b7f18752..95c2d2f5fa3 100644 --- a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.4/GridStyle.js +++ b/workspace-grid@hernejj/files/workspace-grid@hernejj/5.4/GridStyle.js @@ -7,7 +7,7 @@ function GridStyle(applet, cols, rows, height) { } GridStyle.prototype = { - + _init: function(applet, cols, rows, height) { this.scrollby = 'col'; this.applet = applet; @@ -17,43 +17,43 @@ GridStyle.prototype = { this.switch_id = global.window_manager.connect('switch-workspace', Lang.bind(this, this.update)); this.scroll_id = this.applet.actor.connect('scroll-event', Lang.bind(this,this.onMouseScroll)); }, - + cleanup: function() { global.window_manager.disconnect(this.switch_id); this.applet.actor.disconnect(this.scroll_id); }, - + update_grid: function(cols, rows, height) { this.cols = cols; this.rows = rows; this.height = height; this.rebuild(); }, - + onMouseScroll: function(actor, event){ if (this.scrollby == 'row') this.scrollByRow(event); else this.scrollByCol(event); }, - + scrollByCol: function(event) { var idx = global.screen.get_active_workspace_index(); - - if (event.get_scroll_direction() == 0) idx--; + + if (event.get_scroll_direction() == 0) idx--; else if (event.get_scroll_direction() == 1) idx++; - + if(global.screen.get_workspace_by_index(idx) != null) global.screen.get_workspace_by_index(idx).activate(global.get_current_time()); }, - + scrollByRow: function(event) { var idx = global.screen.get_active_workspace_index(); var numworkspaces = this.rows * this.cols; - + var row = Math.floor(idx/this.cols); var col = idx % this.cols ; - + if (event.get_scroll_direction() == 0) { row--; if (row < 0) { @@ -68,12 +68,12 @@ GridStyle.prototype = { col++; } } - + if (col < 0 || col >= this.cols) return; - + idx = row*this.cols + col; - + if(global.screen.get_workspace_by_index(idx) != null) global.screen.get_workspace_by_index(idx).activate(global.get_current_time()); }, @@ -82,23 +82,23 @@ GridStyle.prototype = { if (event.get_button() != 1) return false; global.screen.get_workspace_by_index(actor.index).activate(global.get_current_time()); }, - + setReactivity: function(reactive) { for (let i=0; i < this.button.length; ++i) - this.button[i].reactive = reactive; - }, - + this.button[i].reactive = reactive; + }, + rebuild: function() { this.applet.actor.destroy_all_children(); this.table = new St.Table({homogeneous: false, reactive: true }); this.applet.actor.add(this.table); - + let btn_height = this.height/this.rows; this.button = []; for(let r=0; r < this.rows; r++) { for(let c=0; c < this.cols; c++) { let i = (r*this.cols)+c; - + this.button[i] = new St.Button({ name: 'workspaceButton', style_class: 'workspace-button', reactive: true }); this.button[i].index = i; this.button[i].set_height(btn_height); @@ -112,13 +112,13 @@ GridStyle.prototype = { update: function() { let active_ws = global.screen.get_active_workspace_index(); - + for (let i=0; i < this.button.length; ++i) { if (i == active_ws) this.button[i].add_style_pseudo_class('outlined'); else this.button[i].remove_style_pseudo_class('outlined'); } - } + } }; diff --git a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.4/WorkspaceController.js b/workspace-grid@hernejj/files/workspace-grid@hernejj/5.4/WorkspaceController.js index dda2e4497a6..09ae994cd0a 100755 --- a/workspace-grid@hernejj/files/workspace-grid@hernejj/5.4/WorkspaceController.js +++ b/workspace-grid@hernejj/files/workspace-grid@hernejj/5.4/WorkspaceController.js @@ -5,11 +5,11 @@ function WorkspaceController(cols, rows) { } WorkspaceController.prototype = { - + _init: function(cols, rows) { this.set_workspace_grid(cols, rows); }, - + // Create proper workspace layout geometry within Gnome set_workspace_grid: function (cols, rows) { this.cols = cols; @@ -17,12 +17,12 @@ WorkspaceController.prototype = { this.__equalize_num_workspaces(); global.screen.override_workspace_layout(TOPLEFT, false, rows, cols); }, - + // Update Gnome's view of workspaces to reflect our count based on row*col. __equalize_num_workspaces: function() { let new_ws_count = this.cols * this.rows; let old_ws_count = global.screen.n_workspaces; - + if (new_ws_count > old_ws_count) { for (let i=old_ws_count; i Main.wm._showWorkspaceSwitcher(d, w, b)); + Meta.keybindings_set_custom_handler('switch-to-workspace-down', (d, w, b) => Main.wm._showWorkspaceSwitcher(d, w, b)); } Meta.keybindings_set_custom_handler('switch-to-workspace-left', switchWorkspaceLeft); Meta.keybindings_set_custom_handler('switch-to-workspace-right', switchWorkspaceRight); @@ -44,10 +44,10 @@ function registerKeyBindings(registerUpDownKeyBindings) { } function deregisterKeyBindings() { - Meta.keybindings_set_custom_handler('switch-to-workspace-up', Lang.bind(Main.wm, Main.wm._showWorkspaceSwitcher)); - Meta.keybindings_set_custom_handler('switch-to-workspace-down', Lang.bind(Main.wm, Main.wm._showWorkspaceSwitcher)); - Meta.keybindings_set_custom_handler('switch-to-workspace-left', Lang.bind(Main.wm, Main.wm._showWorkspaceSwitcher)); - Meta.keybindings_set_custom_handler('switch-to-workspace-right', Lang.bind(Main.wm, Main.wm._showWorkspaceSwitcher)); + Meta.keybindings_set_custom_handler('switch-to-workspace-up', (d, w, b) => Main.wm._showWorkspaceSwitcher(d, w, b)); + Meta.keybindings_set_custom_handler('switch-to-workspace-down', (d, w, b) => Main.wm._showWorkspaceSwitcher(d, w, b)); + Meta.keybindings_set_custom_handler('switch-to-workspace-left', (d, w, b) => Main.wm._showWorkspaceSwitcher(d, w, b)); + Meta.keybindings_set_custom_handler('switch-to-workspace-right', (d, w, b) => Main.wm._showWorkspaceSwitcher(d, w, b)); } function switchWorkspaceUp(display, screen, window) { @@ -98,7 +98,7 @@ MyApplet.prototype = { this.metadata = metadata; try { - global.log("workspace-grid@hernejj: v0.7"); + global.log("workspace-grid@hernejj: v0.9"); this.actor.set_style_class_name("workspace-switcher-box"); this.settings = new Settings.AppletSettings(this, "workspace-grid@hernejj", instanceId); this.settings.bindProperty(Settings.BindingDirection.IN, "numCols", "numCols", this.onUpdateNumberOfWorkspaces, null); @@ -111,7 +111,7 @@ MyApplet.prototype = { this.onUpdateStyle(); this.onPanelEditModeChanged(); - global.settings.connect('changed::panel-edit-mode', Lang.bind(this, this.onPanelEditModeChanged)); + global.settings.connect('changed::panel-edit-mode', onPanelEditModeChanged); } catch (e) { global.logError("workspace-grid@hernejj Main Applet Exception: " + e.toString());