Fixed a bug that would prevent the workspace module from being scrolled. (#609)

This commit is contained in:
Jas Singh
2024-12-24 01:09:09 -08:00
committed by GitHub
parent af88c267f4
commit d8a59c1d18
6 changed files with 56 additions and 26 deletions

View File

@@ -162,7 +162,7 @@ const navigateWorkspace = (
while (attempts < workspacesList.length) {
const targetWS = workspacesList[newIndex];
if (!isWorkspaceIgnored(ignoredWorkspaces, targetWS)) {
hyprlandService.message_async(`dispatch workspace ${targetWS}`);
hyprlandService.dispatch('workspace', targetWS.toString());
return;
}
newIndex = (newIndex + step + workspacesList.length) % workspacesList.length;

View File

@@ -1,10 +1,11 @@
import options from 'src/options';
import { createThrottledScrollHandlers, getCurrentMonitorWorkspaces } from './helpers';
import { BarBoxChild, SelfButton } from 'src/lib/types/bar';
import { BarBoxChild } from 'src/lib/types/bar';
import { WorkspaceModule } from './workspaces';
import { bind, Variable } from 'astal';
import { GtkWidget } from 'src/lib/types/widget';
import { Gdk } from 'astal/gtk3';
import { Astal, Gdk } from 'astal/gtk3';
import { isScrollDown, isScrollUp } from 'src/lib/utils';
const { workspaces, scroll_speed } = options.bar.workspaces;
@@ -27,23 +28,27 @@ const Workspaces = (monitor = -1): BarBoxChild => {
boxClass: 'workspaces',
isBox: true,
props: {
setup: (self: SelfButton): void => {
setup: (self: Astal.EventBox): void => {
let scrollHandlers: number;
Variable.derive([bind(scroll_speed)], (scroll_speed) => {
if (scrollHandlers) {
self.disconnect(scrollHandlers);
}
const { throttledScrollUp, throttledScrollDown } = createThrottledScrollHandlers(
scroll_speed,
currentMonitorWorkspaces,
);
const scrollHandlers = self.connect('scroll-event', (_: GtkWidget, event: Gdk.Event) => {
const eventDirection = event.get_scroll_direction()[1];
if (eventDirection === Gdk.ScrollDirection.UP) {
throttledScrollUp();
} else if (eventDirection === Gdk.ScrollDirection.DOWN) {
scrollHandlers = self.connect('scroll-event', (_: GtkWidget, event: Gdk.Event) => {
if (isScrollUp(event)) {
throttledScrollDown();
}
});
self.disconnect(scrollHandlers);
if (isScrollDown(event)) {
throttledScrollUp();
}
});
});
},
},