Skip to content

Commit

Permalink
fix(focus): focused app no been matching correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Aug 29, 2024
1 parent adec6dc commit 998db37
Show file tree
Hide file tree
Showing 17 changed files with 393 additions and 339 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- bad matching fullscreen apps.
- suspended process (ex: Settings) been shown on dock.
- uwp icons not loading correctly.
- bad focused app matching strategy.

## [1.9.11]
### features
Expand Down
218 changes: 109 additions & 109 deletions src/apps/seelen_wm/modules/shared/store/infra.ts
Original file line number Diff line number Diff line change
@@ -1,109 +1,109 @@
import { UserSettingsLoader } from '../../../../settings/modules/shared/store/storeApi';
import { loadThemeCSS, setColorsAsCssVariables } from '../../../../shared';
import { FileChange } from '../../../../shared/events';
import { WindowManager } from '../../../../shared/schemas/WindowManager';
import { configureStore } from '@reduxjs/toolkit';
import { listen as listenGlobal } from '@tauri-apps/api/event';

import { RootActions, RootSlice } from './app';

import { Reservation, Sizing } from '../../layout/domain';
import { AddWindowPayload, DesktopId, FocusAction, UIColors } from './domain';

export const store = configureStore({
reducer: RootSlice.reducer,
devTools: true,
});

export async function loadStore() {
const userSettings = await new UserSettingsLoader().withLayouts().load();
const settings = userSettings.jsonSettings.windowManager;
store.dispatch(RootActions.setAvailableLayouts(userSettings.layouts));
store.dispatch(RootActions.setSettings(settings));
loadSettingsCSS(settings);
loadThemeCSS(userSettings);
}

export async function registerStoreEvents() {
await listenGlobal<any>(FileChange.Settings, async () => {
await loadStore();
});

await listenGlobal<AddWindowPayload>('add-window', (event) => {
store.dispatch(RootActions.addWindow(event.payload));
});

await listenGlobal<number>('remove-window', (event) => {
store.dispatch(RootActions.removeWindow(event.payload));
});

await listenGlobal<void>('force-retiling', () => {
store.dispatch(RootActions.forceUpdate());
});

await listenGlobal<DesktopId>('set-active-workspace', (event) => {
store.dispatch(RootActions.setActiveWorkspace(event.payload));
});

await listenGlobal<number>('set-active-window', (event) => {
store.dispatch(RootActions.setActiveWindow(event.payload));
if (event.payload != 0) {
store.dispatch(RootActions.setLastManagedActivated(event.payload));
}
});

await listenGlobal<Reservation | null>('set-reservation', (event) => {
store.dispatch(RootActions.setReservation(event.payload));
});

await listenGlobal<Sizing>('update-width', (event) => {
store.dispatch(RootActions.updateSizing({ axis: 'x', sizing: event.payload }));
});

await listenGlobal<Sizing>('update-height', (event) => {
store.dispatch(RootActions.updateSizing({ axis: 'y', sizing: event.payload }));
});

await listenGlobal<void>('reset-workspace-size', () => {
store.dispatch(RootActions.resetSizing());
});

await listenGlobal<FocusAction>('focus', (event) => {
store.dispatch(RootActions.focus(event.payload));
});

await listenGlobal<AddWindowPayload>('update-window', (event) => {
store.dispatch(RootActions.removeWindow(event.payload.hwnd));
store.dispatch(RootActions.addWindow(event.payload));
});

await listenGlobal<UIColors>('colors', (event) => {
setColorsAsCssVariables(event.payload);
store.dispatch(RootActions.setColors(event.payload));
});

await listenGlobal(FileChange.Themes, async () => {
const userSettings = await new UserSettingsLoader().load();
loadThemeCSS(userSettings);
});

await listenGlobal(FileChange.Placeholders, async () => {
const userSettings = await new UserSettingsLoader().withLayouts().load();
store.dispatch(RootActions.setAvailableLayouts(userSettings.layouts));
});
}

function loadSettingsCSS(settings: WindowManager) {
const styles = document.documentElement.style;

styles.setProperty('--config-padding', `${settings.workspacePadding}px`);
styles.setProperty('--config-containers-gap', `${settings.workspaceGap}px`);

styles.setProperty('--config-margin-top', `${settings.globalWorkAreaOffset.top}px`);
styles.setProperty('--config-margin-left', `${settings.globalWorkAreaOffset.left}px`);
styles.setProperty('--config-margin-right', `${settings.globalWorkAreaOffset.right}px`);
styles.setProperty('--config-margin-bottom', `${settings.globalWorkAreaOffset.bottom}px`);

styles.setProperty('--config-border-offset', `${settings.border.offset}px`);
styles.setProperty('--config-border-width', `${settings.border.width}px`);
}
import { UserSettingsLoader } from '../../../../settings/modules/shared/store/storeApi';
import { loadThemeCSS, setColorsAsCssVariables } from '../../../../shared';
import { FileChange } from '../../../../shared/events';
import { WindowManager } from '../../../../shared/schemas/WindowManager';
import { configureStore } from '@reduxjs/toolkit';
import { listen as listenGlobal } from '@tauri-apps/api/event';

import { RootActions, RootSlice } from './app';

import { Reservation, Sizing } from '../../layout/domain';
import { AddWindowPayload, DesktopId, FocusAction, UIColors } from './domain';

export const store = configureStore({
reducer: RootSlice.reducer,
devTools: true,
});

export async function loadStore() {
const userSettings = await new UserSettingsLoader().withLayouts().load();
const settings = userSettings.jsonSettings.windowManager;
store.dispatch(RootActions.setAvailableLayouts(userSettings.layouts));
store.dispatch(RootActions.setSettings(settings));
loadSettingsCSS(settings);
loadThemeCSS(userSettings);
}

export async function registerStoreEvents() {
await listenGlobal<any>(FileChange.Settings, async () => {
await loadStore();
});

await listenGlobal<AddWindowPayload>('add-window', (event) => {
store.dispatch(RootActions.addWindow(event.payload));
});

await listenGlobal<number>('remove-window', (event) => {
store.dispatch(RootActions.removeWindow(event.payload));
});

await listenGlobal<void>('force-retiling', () => {
store.dispatch(RootActions.forceUpdate());
});

await listenGlobal<DesktopId>('set-active-workspace', (event) => {
store.dispatch(RootActions.setActiveWorkspace(event.payload));
});

await listenGlobal<number>('set-active-window', (event) => {
store.dispatch(RootActions.setActiveWindow(event.payload));
if (event.payload != 0) {
store.dispatch(RootActions.setLastManagedActivated(event.payload));
}
});

await listenGlobal<Reservation | null>('set-reservation', (event) => {
store.dispatch(RootActions.setReservation(event.payload));
});

await listenGlobal<Sizing>('update-width', (event) => {
store.dispatch(RootActions.updateSizing({ axis: 'x', sizing: event.payload }));
});

await listenGlobal<Sizing>('update-height', (event) => {
store.dispatch(RootActions.updateSizing({ axis: 'y', sizing: event.payload }));
});

await listenGlobal<void>('reset-workspace-size', () => {
store.dispatch(RootActions.resetSizing());
});

await listenGlobal<FocusAction>('focus', (event) => {
store.dispatch(RootActions.focus(event.payload));
});

await listenGlobal<AddWindowPayload>('update-window', (event) => {
store.dispatch(RootActions.removeWindow(event.payload.hwnd));
store.dispatch(RootActions.addWindow(event.payload));
});

await listenGlobal<UIColors>('colors', (event) => {
setColorsAsCssVariables(event.payload);
store.dispatch(RootActions.setColors(event.payload));
});

await listenGlobal(FileChange.Themes, async () => {
const userSettings = await new UserSettingsLoader().load();
loadThemeCSS(userSettings);
});

await listenGlobal(FileChange.Placeholders, async () => {
const userSettings = await new UserSettingsLoader().withLayouts().load();
store.dispatch(RootActions.setAvailableLayouts(userSettings.layouts));
});
}

function loadSettingsCSS(settings: WindowManager) {
const styles = document.documentElement.style;

styles.setProperty('--config-padding', `${settings.workspacePadding}px`);
styles.setProperty('--config-containers-gap', `${settings.workspaceGap}px`);

styles.setProperty('--config-margin-top', `${settings.globalWorkAreaOffset.top}px`);
styles.setProperty('--config-margin-left', `${settings.globalWorkAreaOffset.left}px`);
styles.setProperty('--config-margin-right', `${settings.globalWorkAreaOffset.right}px`);
styles.setProperty('--config-margin-bottom', `${settings.globalWorkAreaOffset.bottom}px`);

styles.setProperty('--config-border-offset', `${settings.border.offset}px`);
styles.setProperty('--config-border-width', `${settings.border.width}px`);
}
134 changes: 67 additions & 67 deletions src/apps/seelenweg/modules/item/infra/StartMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import { StartMenuItem } from '../../../../shared/schemas/SeelenWegItems';
import { WithContextMenu } from '../../../components/WithContextMenu';
import { DraggableItem } from './DraggableItem';
import { getMenuForItem } from './Menu';
import { invoke } from '@tauri-apps/api/core';
import { motion } from 'framer-motion';
import { memo, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

import { BackgroundByLayersV2 } from '../../../components/BackgroundByLayers/infra';

import { Selectors } from '../../shared/store/app';

import { RootState } from '../../shared/store/domain';

interface Props {
item: StartMenuItem;
}

const startMenuExes = ['SearchHost.exe', 'StartMenuExperienceHost.exe'];

export const StartMenu = memo(({ item }: Props) => {
const startMenuOpenRef = useRef(false);

const size = useSelector(Selectors.settings.size);

const isStartMenuOpen = useSelector((state: RootState) =>
startMenuExes.includes(Selectors.focusedExecutable(state)),
);

const { t } = useTranslation();

useEffect(() => {
if (!isStartMenuOpen) {
setTimeout(() => {
startMenuOpenRef.current = isStartMenuOpen;
}, 100);
} else {
startMenuOpenRef.current = isStartMenuOpen;
}
}, [isStartMenuOpen]);

return (
<DraggableItem item={item}>
<WithContextMenu items={getMenuForItem(t, item)}>
<motion.div
className="weg-item"
initial={{ scale: 0 }}
animate={{ scale: 1 }}
style={{ height: size, aspectRatio: '1/1' }}
onClick={() => {
if (!startMenuOpenRef.current) {
invoke('send_keys', { keys: '{win}' });
}
}}
onContextMenu={(e) => e.stopPropagation()}
>
<BackgroundByLayersV2 prefix="item" />
<div className="weg-item-icon">
<div className="weg-item-icon-start" />
</div>
</motion.div>
</WithContextMenu>
</DraggableItem>
);
});
import { StartMenuItem } from '../../../../shared/schemas/SeelenWegItems';
import { WithContextMenu } from '../../../components/WithContextMenu';
import { DraggableItem } from './DraggableItem';
import { getMenuForItem } from './Menu';
import { invoke } from '@tauri-apps/api/core';
import { motion } from 'framer-motion';
import { memo, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';

import { BackgroundByLayersV2 } from '../../../components/BackgroundByLayers/infra';

import { Selectors } from '../../shared/store/app';

import { RootState } from '../../shared/store/domain';

interface Props {
item: StartMenuItem;
}

const startMenuExes = ['SearchHost.exe', 'StartMenuExperienceHost.exe'];

export const StartMenu = memo(({ item }: Props) => {
const startMenuOpenRef = useRef(false);

const size = useSelector(Selectors.settings.size);

const isStartMenuOpen = useSelector((state: RootState) =>
startMenuExes.includes(Selectors.focusedApp(state)?.exe || ''),
);

const { t } = useTranslation();

useEffect(() => {
if (!isStartMenuOpen) {
setTimeout(() => {
startMenuOpenRef.current = isStartMenuOpen;
}, 100);
} else {
startMenuOpenRef.current = isStartMenuOpen;
}
}, [isStartMenuOpen]);

return (
<DraggableItem item={item}>
<WithContextMenu items={getMenuForItem(t, item)}>
<motion.div
className="weg-item"
initial={{ scale: 0 }}
animate={{ scale: 1 }}
style={{ height: size, aspectRatio: '1/1' }}
onClick={() => {
if (!startMenuOpenRef.current) {
invoke('send_keys', { keys: '{win}' });
}
}}
onContextMenu={(e) => e.stopPropagation()}
>
<BackgroundByLayersV2 prefix="item" />
<div className="weg-item-icon">
<div className="weg-item-icon-start" />
</div>
</motion.div>
</WithContextMenu>
</DraggableItem>
);
});
Loading

0 comments on commit 998db37

Please sign in to comment.