Skip to content

Commit

Permalink
Update the ignored workspaces rule to a regex instead of array.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jas-SinghFSU committed Sep 25, 2024
1 parent 91bd49e commit 69c4682
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
3 changes: 0 additions & 3 deletions lib/types/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,3 @@ export type ColorMapKey = keyof typeof defaultColorMap;
export type ColorMapValue = (typeof defaultColorMap)[ColorMapKey];

export type ScalingPriority = 'gdk' | 'hyprland' | 'both';

export type IgnoredWorkspace = number | string;
export type IgnoredWorkspaces = IgnoredWorkspace[];
26 changes: 8 additions & 18 deletions modules/bar/workspaces/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const hyprland = await Service.import('hyprland');

import { IgnoredWorkspace, IgnoredWorkspaces } from 'lib/types/options';
import { MonitorMap, WorkspaceMap, WorkspaceRule } from 'lib/types/workspace';
import options from 'options';
import { Variable } from 'types/variable';
Expand Down Expand Up @@ -72,28 +71,19 @@ type ThrottledScrollHandlers = {
throttledScrollDown: () => void;
};

export const isWorkspaceIgnored = (
ignoredWorkspaces: Variable<IgnoredWorkspaces>,
workspaceNumber: number,
): boolean => {
const ignoredValues = ignoredWorkspaces.value;
export const isWorkspaceIgnored = (ignoredWorkspaces: Variable<string>, workspaceNumber: number): boolean => {
if (ignoredWorkspaces.value === '') return false;

return ignoredValues.some((ignore: IgnoredWorkspace) => {
if (typeof ignore === 'number') {
return ignore === workspaceNumber;
}
if (typeof ignore === 'string') {
return new RegExp(ignore).test(workspaceNumber.toString());
}
return true;
});
const ignoredWsRegex = new RegExp(ignoredWorkspaces.value);

return ignoredWsRegex.test(workspaceNumber.toString());
};

const navigateWorkspace = (
direction: 'next' | 'prev',
currentMonitorWorkspaces: Variable<number[]>,
activeWorkspaces: boolean,
ignoredWorkspaces: Variable<IgnoredWorkspaces>,
ignoredWorkspaces: Variable<string>,
): void => {
const workspacesList = activeWorkspaces
? hyprland.workspaces.filter((ws) => hyprland.active.monitor.id === ws.monitorID).map((ws) => ws.id)
Expand All @@ -120,15 +110,15 @@ const navigateWorkspace = (
export const goToNextWS = (
currentMonitorWorkspaces: Variable<number[]>,
activeWorkspaces: boolean,
ignoredWorkspaces: Variable<IgnoredWorkspaces>,
ignoredWorkspaces: Variable<string>,
): void => {
navigateWorkspace('next', currentMonitorWorkspaces, activeWorkspaces, ignoredWorkspaces);
};

export const goToPrevWS = (
currentMonitorWorkspaces: Variable<number[]>,
activeWorkspaces: boolean,
ignoredWorkspaces: Variable<IgnoredWorkspaces>,
ignoredWorkspaces: Variable<string>,
): void => {
navigateWorkspace('prev', currentMonitorWorkspaces, activeWorkspaces, ignoredWorkspaces);
};
Expand Down
3 changes: 1 addition & 2 deletions options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
ActiveWsIndicator,
BarButtonStyles,
BarLocation,
IgnoredWorkspaces,
NotificationAnchor,
OSDAnchor,
OSDOrientation,
Expand Down Expand Up @@ -862,7 +861,7 @@ const options = mkOptions(OPTIONS, {
},
workspaces: {
show_icons: opt(false),
ignored: opt<IgnoredWorkspaces>([]),
ignored: opt(''),
show_numbered: opt(false),
showWsIcons: opt(false),
numbered_active_indicator: opt<ActiveWsIndicator>('underline'),
Expand Down
6 changes: 2 additions & 4 deletions widget/settings/pages/config/bar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,8 @@ export const BarSettings = (): Scrollable<Gtk.Widget, Gtk.Widget> => {
Option({
opt: options.bar.workspaces.ignored,
title: 'Ignored Workspaces',
subtitle:
'An array of workspace numbers to ignore.\n' +
'A regular expression can be passed in the array to ignore workspaces that match the regex.',
type: 'object',
subtitle: 'A regex that defines workspaces to ignore',
type: 'string',
}),

/*
Expand Down

0 comments on commit 69c4682

Please sign in to comment.