bar: focus mode: fix workspaces

This commit is contained in:
end-4
2024-03-01 21:53:31 +07:00
parent e8e368c82f
commit a3d4523f2f
@@ -15,6 +15,8 @@ const dummyActiveWs = Box({ className: 'bar-ws-focus bar-ws-focus-active' }); //
const dummyOccupiedWs = Box({ className: 'bar-ws-focus bar-ws-focus-occupied' }); // Not shown. Only for getting size props const dummyOccupiedWs = Box({ className: 'bar-ws-focus bar-ws-focus-occupied' }); // Not shown. Only for getting size props
const WS_TAKEN_WIDTH_MULTIPLIER = 1.4; const WS_TAKEN_WIDTH_MULTIPLIER = 1.4;
const floor = Math.floor;
const ceil = Math.ceil;
// Font size = workspace id // Font size = workspace id
const WorkspaceContents = (count = 10) => { const WorkspaceContents = (count = 10) => {
@@ -114,8 +116,8 @@ const WorkspaceContents = (count = 10) => {
cr.arc(centerX, height / 2, workspaceRadius, 0, 2 * Math.PI); cr.arc(centerX, height / 2, workspaceRadius, 0, 2 * Math.PI);
cr.fill(); cr.fill();
// What if shrinking // What if shrinking
if (i == immediateActiveWs - 1 && immediateActiveWs > activeWs) { // To right if (i == floor(activeWs) && immediateActiveWs > activeWs) { // To right
const widthPercentage = 1 - (immediateActiveWs - activeWs); const widthPercentage = 1 - (ceil(activeWs) - activeWs);
const leftX = centerX; const leftX = centerX;
const wsWidth = (activeWorkspaceWidth - (workspaceDiameter * 1.5)) * (1 - widthPercentage); const wsWidth = (activeWorkspaceWidth - (workspaceDiameter * 1.5)) * (1 - widthPercentage);
cr.rectangle(leftX, height / 2 - workspaceRadius, wsWidth, workspaceDiameter); cr.rectangle(leftX, height / 2 - workspaceRadius, wsWidth, workspaceDiameter);
@@ -123,8 +125,8 @@ const WorkspaceContents = (count = 10) => {
cr.arc(leftX + wsWidth, height / 2, workspaceRadius, 0, Math.PI * 2); cr.arc(leftX + wsWidth, height / 2, workspaceRadius, 0, Math.PI * 2);
cr.fill(); cr.fill();
} }
else if (i == immediateActiveWs + 1 && immediateActiveWs < activeWs) { // To left else if (i == ceil(activeWs) && immediateActiveWs < activeWs) { // To left
const widthPercentage = activeWs - immediateActiveWs; const widthPercentage = activeWs - floor(activeWs);
const rightX = centerX; const rightX = centerX;
const wsWidth = (activeWorkspaceWidth - (workspaceDiameter * 1.5)) * widthPercentage; const wsWidth = (activeWorkspaceWidth - (workspaceDiameter * 1.5)) * widthPercentage;
const leftX = rightX - wsWidth; const leftX = rightX - wsWidth;
@@ -138,6 +140,7 @@ const WorkspaceContents = (count = 10) => {
let widthPercentage, leftX, rightX, activeWsWidth; let widthPercentage, leftX, rightX, activeWsWidth;
cr.setSourceRGBA(activebg.red, activebg.green, activebg.blue, activebg.alpha); cr.setSourceRGBA(activebg.red, activebg.green, activebg.blue, activebg.alpha);
if (immediateActiveWs > activeWs) { // To right if (immediateActiveWs > activeWs) { // To right
const immediateActiveWs = ceil(activeWs);
widthPercentage = immediateActiveWs - activeWs; widthPercentage = immediateActiveWs - activeWs;
rightX = -workspaceRadius + workspaceDiameter * WS_TAKEN_WIDTH_MULTIPLIER * (count - 1) + activeWorkspaceWidth - ((count - immediateActiveWs) * workspaceDiameter * WS_TAKEN_WIDTH_MULTIPLIER); rightX = -workspaceRadius + workspaceDiameter * WS_TAKEN_WIDTH_MULTIPLIER * (count - 1) + activeWorkspaceWidth - ((count - immediateActiveWs) * workspaceDiameter * WS_TAKEN_WIDTH_MULTIPLIER);
activeWsWidth = (activeWorkspaceWidth - (workspaceDiameter * 1.5)) * (1 - widthPercentage); activeWsWidth = (activeWorkspaceWidth - (workspaceDiameter * 1.5)) * (1 - widthPercentage);
@@ -151,6 +154,7 @@ const WorkspaceContents = (count = 10) => {
cr.fill(); cr.fill();
} }
else { // To left else { // To left
const immediateActiveWs = floor(activeWs);
widthPercentage = 1 - (activeWs - immediateActiveWs); widthPercentage = 1 - (activeWs - immediateActiveWs);
leftX = -workspaceRadius + (workspaceDiameter * WS_TAKEN_WIDTH_MULTIPLIER * immediateActiveWs); leftX = -workspaceRadius + (workspaceDiameter * WS_TAKEN_WIDTH_MULTIPLIER * immediateActiveWs);
activeWsWidth = (activeWorkspaceWidth - (workspaceDiameter * 1.5)) * widthPercentage activeWsWidth = (activeWorkspaceWidth - (workspaceDiameter * 1.5)) * widthPercentage