Fixed an issue that would cause the scroll direction to be inverted on secondary monitors. (#683)
* Fixed an issue that would cause the scroll direction to be inverted on secondary monitors. * Update import paths and tsconfig.
This commit is contained in:
@@ -5,7 +5,7 @@ import options from 'src/options';
|
||||
import { BarBoxChild } from 'src/lib/types/bar.js';
|
||||
import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers.js';
|
||||
import Variable from 'astal/variable';
|
||||
import { bind } from 'astal/binding.js';
|
||||
import { bind } from 'astal';
|
||||
import AstalBattery from 'gi://AstalBattery?version=0.1';
|
||||
import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers';
|
||||
import { getBatteryIcon } from './helpers';
|
||||
|
||||
@@ -3,8 +3,7 @@ import options from 'src/options.js';
|
||||
import { openMenu } from '../../utils/menu.js';
|
||||
import { BarBoxChild } from 'src/lib/types/bar.js';
|
||||
import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers.js';
|
||||
import { bind } from 'astal/binding.js';
|
||||
import Variable from 'astal/variable.js';
|
||||
import { Variable, bind } from 'astal';
|
||||
import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers.js';
|
||||
import AstalBluetooth from 'gi://AstalBluetooth?version=0.1';
|
||||
import { Astal } from 'astal/gtk3';
|
||||
|
||||
@@ -3,9 +3,8 @@ import options from 'src/options.js';
|
||||
import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers.js';
|
||||
import { generateMediaLabel } from './helpers/index.js';
|
||||
import { mprisService } from 'src/lib/constants/services.js';
|
||||
import Variable from 'astal/variable.js';
|
||||
import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers.js';
|
||||
import { bind } from 'astal/binding.js';
|
||||
import { bind, Variable } from 'astal';
|
||||
import { BarBoxChild } from 'src/lib/types/bar.js';
|
||||
import { Astal } from 'astal/gtk3';
|
||||
import { activePlayer, mediaAlbum, mediaArtist, mediaTitle } from 'src/globals/media.js';
|
||||
|
||||
@@ -2,8 +2,7 @@ import { runAsyncCommand, throttledScrollHandler } from '../../utils/helpers.js'
|
||||
import options from '../../../../options.js';
|
||||
import { openMenu } from '../../utils/menu.js';
|
||||
import { getDistroIcon } from '../../../../lib/utils.js';
|
||||
import { bind } from 'astal/binding.js';
|
||||
import Variable from 'astal/variable.js';
|
||||
import { Variable, bind } from 'astal';
|
||||
import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers.js';
|
||||
import { BarBoxChild } from 'src/lib/types/bar.js';
|
||||
import { Astal } from 'astal/gtk3';
|
||||
|
||||
@@ -4,7 +4,6 @@ import AstalTray from 'gi://AstalTray?version=0.1';
|
||||
import { bind, Gio, Variable } from 'astal';
|
||||
import { BarBoxChild } from 'src/lib/types/bar';
|
||||
import { Gdk, Gtk } from 'astal/gtk3';
|
||||
import { BindableChild } from 'astal/gtk3/astalify';
|
||||
|
||||
const systemtray = AstalTray.get_default();
|
||||
const { ignore, customIcons } = options.bar.systray;
|
||||
@@ -137,7 +136,7 @@ interface MenuCustomIconProps {
|
||||
|
||||
interface MenuEntryProps {
|
||||
item: AstalTray.TrayItem;
|
||||
child?: BindableChild;
|
||||
child?: JSX.Element;
|
||||
}
|
||||
|
||||
export { SysTray };
|
||||
|
||||
@@ -2,8 +2,7 @@ import { audioService } from 'src/lib/constants/services.js';
|
||||
import { openMenu } from '../../utils/menu.js';
|
||||
import options from 'src/options';
|
||||
import { runAsyncCommand, throttledScrollHandler } from 'src/components/bar/utils/helpers.js';
|
||||
import Variable from 'astal/variable.js';
|
||||
import { bind } from 'astal/binding.js';
|
||||
import { bind, Variable } from 'astal';
|
||||
import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers.js';
|
||||
import { getIcon } from './helpers/index.js';
|
||||
import { BarBoxChild } from 'src/lib/types/bar.js';
|
||||
|
||||
@@ -169,21 +169,14 @@ function isWorkspaceIgnored(ignoredWorkspacesVariable: Variable<string>, workspa
|
||||
* @param onlyActiveWorkspaces - Whether to only include active (occupied) workspaces when navigating.
|
||||
* @param ignoredWorkspacesVariable - A Variable that contains the ignored workspaces pattern.
|
||||
*/
|
||||
function navigateWorkspace(
|
||||
direction: 'next' | 'prev',
|
||||
currentMonitorWorkspacesVariable: Variable<number[]>,
|
||||
onlyActiveWorkspaces: boolean,
|
||||
ignoredWorkspacesVariable: Variable<string>,
|
||||
): void {
|
||||
function navigateWorkspace(direction: 'next' | 'prev', ignoredWorkspacesVariable: Variable<string>): void {
|
||||
const allHyprlandWorkspaces = hyprlandService.get_workspaces() || [];
|
||||
|
||||
const activeWorkspaceIds = allHyprlandWorkspaces
|
||||
.filter((workspaceInstance) => hyprlandService.focusedMonitor.id === workspaceInstance.monitor?.id)
|
||||
.map((workspaceInstance) => workspaceInstance.id);
|
||||
|
||||
const assignedOrOccupiedWorkspaces = onlyActiveWorkspaces
|
||||
? activeWorkspaceIds
|
||||
: currentMonitorWorkspacesVariable.get() || Array.from({ length: workspaces.get() }, (_, index) => index + 1);
|
||||
const assignedOrOccupiedWorkspaces = activeWorkspaceIds.sort((a, b) => a - b);
|
||||
|
||||
if (assignedOrOccupiedWorkspaces.length === 0) {
|
||||
return;
|
||||
@@ -213,12 +206,8 @@ function navigateWorkspace(
|
||||
* @param onlyActiveWorkspaces - Whether to only navigate among active (occupied) workspaces.
|
||||
* @param ignoredWorkspacesVariable - A Variable that contains the ignored workspaces pattern.
|
||||
*/
|
||||
export function goToNextWorkspace(
|
||||
currentMonitorWorkspacesVariable: Variable<number[]>,
|
||||
onlyActiveWorkspaces: boolean,
|
||||
ignoredWorkspacesVariable: Variable<string>,
|
||||
): void {
|
||||
navigateWorkspace('next', currentMonitorWorkspacesVariable, onlyActiveWorkspaces, ignoredWorkspacesVariable);
|
||||
export function goToNextWorkspace(ignoredWorkspacesVariable: Variable<string>): void {
|
||||
navigateWorkspace('next', ignoredWorkspacesVariable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,12 +217,8 @@ export function goToNextWorkspace(
|
||||
* @param onlyActiveWorkspaces - Whether to only navigate among active (occupied) workspaces.
|
||||
* @param ignoredWorkspacesVariable - A Variable that contains the ignored workspaces pattern.
|
||||
*/
|
||||
export function goToPreviousWorkspace(
|
||||
currentMonitorWorkspacesVariable: Variable<number[]>,
|
||||
onlyActiveWorkspaces: boolean,
|
||||
ignoredWorkspacesVariable: Variable<string>,
|
||||
): void {
|
||||
navigateWorkspace('prev', currentMonitorWorkspacesVariable, onlyActiveWorkspaces, ignoredWorkspacesVariable);
|
||||
export function goToPreviousWorkspace(ignoredWorkspacesVariable: Variable<string>): void {
|
||||
navigateWorkspace('prev', ignoredWorkspacesVariable);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -263,29 +248,24 @@ export function throttle<T extends (...args: unknown[]) => void>(func: T, limit:
|
||||
* Creates throttled scroll handlers that navigate workspaces upon scrolling, respecting the configured scroll speed.
|
||||
*
|
||||
* @param scrollSpeed - The factor by which the scroll navigation is throttled.
|
||||
* @param currentMonitorWorkspacesVariable - A Variable containing the current monitor's workspace numbers.
|
||||
* @param onlyActiveWorkspaces - Whether to only navigate among active (occupied) workspaces.
|
||||
*
|
||||
* @returns An object containing two functions (`throttledScrollUp` and `throttledScrollDown`), both throttled.
|
||||
*/
|
||||
export function initThrottledScrollHandlers(
|
||||
scrollSpeed: number,
|
||||
currentMonitorWorkspacesVariable: Variable<number[]>,
|
||||
onlyActiveWorkspaces: boolean = true,
|
||||
): ThrottledScrollHandlers {
|
||||
export function initThrottledScrollHandlers(scrollSpeed: number): ThrottledScrollHandlers {
|
||||
const throttledScrollUp = throttle(() => {
|
||||
if (reverse_scroll.get()) {
|
||||
goToPreviousWorkspace(currentMonitorWorkspacesVariable, onlyActiveWorkspaces, ignored);
|
||||
goToPreviousWorkspace(ignored);
|
||||
} else {
|
||||
goToNextWorkspace(currentMonitorWorkspacesVariable, onlyActiveWorkspaces, ignored);
|
||||
goToNextWorkspace(ignored);
|
||||
}
|
||||
}, 200 / scrollSpeed);
|
||||
|
||||
const throttledScrollDown = throttle(() => {
|
||||
if (reverse_scroll.get()) {
|
||||
goToNextWorkspace(currentMonitorWorkspacesVariable, onlyActiveWorkspaces, ignored);
|
||||
goToNextWorkspace(ignored);
|
||||
} else {
|
||||
goToPreviousWorkspace(currentMonitorWorkspacesVariable, onlyActiveWorkspaces, ignored);
|
||||
goToPreviousWorkspace(ignored);
|
||||
}
|
||||
}, 200 / scrollSpeed);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import options from 'src/options';
|
||||
import { initThrottledScrollHandlers, getWorkspacesForMonitor } from './helpers';
|
||||
import { initThrottledScrollHandlers } from './helpers';
|
||||
import { BarBoxChild } from 'src/lib/types/bar';
|
||||
import { WorkspaceModule } from './workspaces';
|
||||
import { bind, Variable } from 'astal';
|
||||
@@ -7,15 +7,9 @@ import { GtkWidget } from 'src/lib/types/widget';
|
||||
import { Astal, Gdk } from 'astal/gtk3';
|
||||
import { isScrollDown, isScrollUp } from 'src/lib/utils';
|
||||
|
||||
const { workspaces, scroll_speed } = options.bar.workspaces;
|
||||
const { scroll_speed } = options.bar.workspaces;
|
||||
|
||||
const Workspaces = (monitor = -1): BarBoxChild => {
|
||||
const currentMonitorWorkspaces = Variable(getWorkspacesForMonitor(monitor));
|
||||
|
||||
workspaces.subscribe(() => {
|
||||
currentMonitorWorkspaces.set(getWorkspacesForMonitor(monitor));
|
||||
});
|
||||
|
||||
const component = (
|
||||
<box className={'workspaces-box-container'}>
|
||||
<WorkspaceModule monitor={monitor} />
|
||||
@@ -35,18 +29,15 @@ const Workspaces = (monitor = -1): BarBoxChild => {
|
||||
self.disconnect(scrollHandlers);
|
||||
}
|
||||
|
||||
const { throttledScrollUp, throttledScrollDown } = initThrottledScrollHandlers(
|
||||
scroll_speed,
|
||||
currentMonitorWorkspaces,
|
||||
);
|
||||
const { throttledScrollUp, throttledScrollDown } = initThrottledScrollHandlers(scroll_speed);
|
||||
|
||||
scrollHandlers = self.connect('scroll-event', (_: GtkWidget, event: Gdk.Event) => {
|
||||
if (isScrollUp(event)) {
|
||||
throttledScrollDown();
|
||||
throttledScrollUp();
|
||||
}
|
||||
|
||||
if (isScrollDown(event)) {
|
||||
throttledScrollUp();
|
||||
throttledScrollDown();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user