Skip to content

Commit

Permalink
Improve backward compatibility to 4.2 and fix remaining 5.4 bugs (#4410)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcalixte authored Aug 9, 2022
1 parent 1a68943 commit 78d74a3
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,51 @@ function BarIndicatorStyle(applet, cols, rows, height) {
}

BarIndicatorStyle.prototype = {

_init: function(applet, cols, rows, height) {
this.applet = applet;
this.button = [];
this.update_grid(cols, rows, height);
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) {
Expand All @@ -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();
Expand All @@ -89,20 +89,20 @@ 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;
},

onWorkspaceButtonClicked: function(actor, event) {
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();

Expand All @@ -117,7 +117,7 @@ BarIndicatorStyle.prototype = {
this.button = [];
for ( let i=0; i<global.screen.n_workspaces; ++i ) {
this.button[i] = new St.Button({ name: 'workspaceButton', style_class: 'workspace-button', reactive: true });

let text = (i+1).toString();
let label = new St.Label({ text: text });
label.set_style("font-weight: bold");
Expand All @@ -137,19 +137,19 @@ BarIndicatorStyle.prototype = {
let active_row = Math.floor(active_ws/this.cols);
let low = (active_row)*this.cols;
let high = low + this.cols;

// If the user added or removed workspaces external to this applet then
// we could end up with a selected workspaces that is out of bounds. Just
// revert to displaying the last row in that case.
if (active_ws >= nworks) {
high = nworks - 1;
low = high - this.cols;
}

for (let i=0; i < nworks; ++i) {
if (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');
Expand All @@ -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();
Expand All @@ -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;

Expand All @@ -200,20 +200,20 @@ 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');

let sel_avg = (selected_txt_color.red + selected_txt_color.green + selected_txt_color.blue)/3;
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function GridStyle(applet, cols, rows, height) {
}

GridStyle.prototype = {

_init: function(applet, cols, rows, height) {
this.scrollby = 'col';
this.applet = applet;
Expand All @@ -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) {
Expand All @@ -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());
},
Expand All @@ -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);
Expand All @@ -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');
}
}
}
};

Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ 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;
this.rows = rows;
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<new_ws_count; i++)
global.screen.append_new_workspace(false, global.get_current_time());
Expand All @@ -35,7 +35,7 @@ WorkspaceController.prototype = {
}
}
},

// This applet is going away. Revert to allowing Cinnamon to control workspaces.
release_control: function() {
this.set_workspace_grid(-1, 1); // Set to no rows, and a single desktop
Expand Down
Loading

0 comments on commit 78d74a3

Please sign in to comment.