Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
orangci authored Dec 24, 2024
2 parents 1c56347 + 65140db commit 27f2df3
Show file tree
Hide file tree
Showing 36 changed files with 540 additions and 101 deletions.
8 changes: 7 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@

# Define .overlay to expose the package as pkgs.hyprpanel based on the system
overlay = final: prev: {
hyprpanel = self.packages.${prev.stdenv.system}.default;
hyprpanel = prev.writeShellScriptBin "hyprpanel" ''
if [ "$#" -eq 0 ]; then
exec ${self.packages.${final.stdenv.system}.default}/bin/hyprpanel
else
exec ${astal.packages.${final.stdenv.system}.io}/bin/astal -i hyprpanel "$@"
fi
'';
};
};
}
9 changes: 7 additions & 2 deletions scripts/checkUpdates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
check_arch_updates() {
official_updates=0
aur_updates=0
if command -v paru &> /dev/null; then
aur_helper="paru"
else
aur_helper="yay"
fi

if [ "$1" = "-y" ]; then
aur_updates=$(yay -Qum 2>/dev/null | wc -l)
aur_updates=$($aur_helper -Qum 2>/dev/null | wc -l)
elif [ "$1" = "-p" ]; then
official_updates=$(checkupdates 2>/dev/null | wc -l)
else
official_updates=$(checkupdates 2>/dev/null | wc -l)
aur_updates=$(yay -Qum 2>/dev/null | wc -l)
aur_updates=$($aur_helper -Qum 2>/dev/null | wc -l)
fi

total_updates=$((official_updates + aur_updates))
Expand Down
8 changes: 5 additions & 3 deletions src/components/bar/modules/netstat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const {
rateUnit,
dynamicIcon,
icon,
networkInLabel,
networkOutLabel,
round,
leftClick,
rightClick,
Expand Down Expand Up @@ -47,11 +49,11 @@ export const Netstat = (): BarBoxChild => {
const renderNetworkLabel = (lblType: NetstatLabelType, networkService: NetworkResourceData): string => {
switch (lblType) {
case 'in':
return ` ${networkService.in}`;
return `${networkInLabel.get()} ${networkService.in}`;
case 'out':
return ` ${networkService.out}`;
return `${networkOutLabel.get()} ${networkService.out}`;
default:
return ` ${networkService.in} ${networkService.out}`;
return `${networkInLabel.get()} ${networkService.in} ${networkOutLabel.get()} ${networkService.out}`;
}
};

Expand Down
8 changes: 8 additions & 0 deletions src/components/bar/modules/updates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
updateCommand,
label,
padZero,
autoHide,
pollingInterval,
icon,
leftClick,
Expand All @@ -21,6 +22,7 @@ const {

const pendingUpdates: Variable<string> = Variable('0');
const postInputUpdater = Variable(true);
const isVis = Variable(!autoHide.get());

const processUpdateCount = (updateCount: string): string => {
if (!padZero.get()) return updateCount;
Expand All @@ -37,9 +39,14 @@ const updatesPoller = new BashPoller<string, []>(

updatesPoller.initialize('updates');

Variable.derive([bind(autoHide)], (autoHideModule) => {
isVis.set(!autoHideModule || (autoHideModule && parseFloat(pendingUpdates.get()) > 0));
});

const updatesIcon = Variable.derive(
[bind(icon.pending), bind(icon.updated), bind(pendingUpdates)],
(pendingIcon, updatedIcon, pUpdates) => {
isVis.set(!autoHide.get() || (autoHide.get() && parseFloat(pUpdates) > 0));
return parseFloat(pUpdates) === 0 ? updatedIcon : pendingIcon;
},
);
Expand All @@ -49,6 +56,7 @@ export const Updates = (): BarBoxChild => {
textIcon: updatesIcon(),
tooltipText: bind(pendingUpdates).as((v) => `${v} updates available`),
boxClass: 'updates',
isVis: isVis,
label: bind(pendingUpdates),
showLabelBinding: bind(label),
props: {
Expand Down
19 changes: 9 additions & 10 deletions src/components/bar/modules/window_title/helpers/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import AstalHyprland from 'gi://AstalHyprland?version=0.1';
* This function searches for a matching window title in the predefined `windowTitleMap` based on the class of the provided window.
* If a match is found, it returns an object containing the icon and label for the window. If no match is found, it returns a default icon and label.
*
* @param windowtitle The window object containing the class information.
* @param client The window object containing the class information.
*
* @returns An object containing the icon and label for the window.
*/
export const getWindowMatch = (windowtitle: AstalHyprland.Client): Record<string, string> => {
export const getWindowMatch = (client: AstalHyprland.Client): Record<string, string> => {
const windowTitleMap = [
// user provided values
...options.bar.windowtitle.title_map.get(),
Expand Down Expand Up @@ -119,17 +119,17 @@ export const getWindowMatch = (windowtitle: AstalHyprland.Client): Record<string
['^$', '󰇄', 'Desktop'],

// Fallback icon
['(.+)', '󰣆', `${capitalizeFirstLetter(windowtitle?.class ?? 'Unknown')}`],
['(.+)', '󰣆', `${capitalizeFirstLetter(client?.class ?? 'Unknown')}`],
];

if (!windowtitle?.class) {
if (!client?.class) {
return {
icon: '󰇄',
label: 'Desktop',
};
}

const foundMatch = windowTitleMap.find((wt) => RegExp(wt[0]).test(windowtitle?.class.toLowerCase()));
const foundMatch = windowTitleMap.find((wt) => RegExp(wt[0]).test(client?.class.toLowerCase()));

if (!foundMatch || foundMatch.length !== 3) {
return {
Expand Down Expand Up @@ -157,13 +157,12 @@ export const getWindowMatch = (windowtitle: AstalHyprland.Client): Record<string
* @returns The title of the window as a string.
*/
export const getTitle = (client: AstalHyprland.Client, useCustomTitle: boolean, useClassName: boolean): string => {
if (client === null) return getWindowMatch(client).label;

if (useCustomTitle) return getWindowMatch(client).label;
if (useClassName) return client.class;
if (client === null || useCustomTitle) return getWindowMatch(client).label;

const title = client.title;
// If the title is empty or only filled with spaces, fallback to the class name

if (!title || useClassName) return client.class;

if (title.length === 0 || title.match(/^ *$/)) {
return client.class;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/bar/modules/workspaces/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 15 additions & 10 deletions src/components/bar/modules/workspaces/index.tsx
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
}
});
});
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/bar/modules/workspaces/workspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const WorkspaceModule = ({ monitor }: WorkspaceModuleProps): JSX.Element
self.toggleClassName('active', activeWorkspace === wsId);
self.toggleClassName(
'occupied',
(hyprlandService.get_workspace(wsId)?.get_clients().length || 0) > 0,
(hyprlandService.get_workspace(wsId)?.get_clients()?.length || 0) > 0,
);
}}
/>
Expand Down
92 changes: 90 additions & 2 deletions src/components/bar/settings/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ export const CustomModuleSettings = (): JSX.Element => {
<Option
opt={options.bar.customModules.netstat.networkInterface}
title="Network Interface"
subtitle="Wiki: https://hyprpanel.com/configuration/panel.html#custom-modules"
subtitle={
'Name of the network interface to poll.\n' +
"HINT: Get a list of interfaces with 'cat /proc/net/dev"
}
type="string"
/>
<Option
Expand All @@ -151,6 +154,12 @@ export const CustomModuleSettings = (): JSX.Element => {
/>
<Option opt={options.bar.customModules.netstat.icon} title="Netstat Icon" type="string" />
<Option opt={options.bar.customModules.netstat.label} title="Show Label" type="boolean" />
<Option opt={options.bar.customModules.netstat.networkInLabel} title="Network In Label" type="string" />
<Option
opt={options.bar.customModules.netstat.networkOutLabel}
title="Network Out Label"
type="string"
/>
<Option
opt={options.bar.customModules.netstat.rateUnit}
title="Rate Unit"
Expand All @@ -167,7 +176,7 @@ export const CustomModuleSettings = (): JSX.Element => {
<Option opt={options.bar.customModules.netstat.round} title="Round" type="boolean" />
<Option
opt={options.bar.customModules.netstat.pollingInterval}
title="Polling Interval"
title="Polling Interval (ms)"
type="number"
min={100}
max={60 * 24 * 1000}
Expand Down Expand Up @@ -218,6 +227,12 @@ export const CustomModuleSettings = (): JSX.Element => {
/>
<Option opt={options.bar.customModules.updates.icon.updated} title="No Updates Icon" type="string" />
<Option opt={options.bar.customModules.updates.label} title="Show Label" type="boolean" />
<Option
opt={options.bar.customModules.updates.autoHide}
title="Auto Hide"
subtitle="Hides module when no updates are available."
type="boolean"
/>
<Option opt={options.bar.customModules.updates.padZero} title="Pad with 0" type="boolean" />
<Option opt={options.theme.bar.buttons.modules.updates.spacing} title="Spacing" type="string" />
<Option
Expand Down Expand Up @@ -280,6 +295,79 @@ export const CustomModuleSettings = (): JSX.Element => {
<Option opt={options.bar.customModules.weather.middleClick} title="Middle Click" type="string" />
<Option opt={options.bar.customModules.weather.scrollUp} title="Scroll Up" type="string" />
<Option opt={options.bar.customModules.weather.scrollDown} title="Scroll Down" type="string" />

{/* Hyprsunset Section */}
<Header title="Hyprsunset" />
<Option
opt={options.bar.customModules.hyprsunset.temperature}
title="Temperature"
subtitle="Ex: 1000k, 2000k, 5000k, etc."
type="string"
/>
<Option
opt={options.theme.bar.buttons.modules.hyprsunset.enableBorder}
title="Button Border"
type="boolean"
/>
<Option opt={options.bar.customModules.hyprsunset.onIcon} title="Enabled Icon" type="string" />
<Option opt={options.bar.customModules.hyprsunset.offIcon} title="Disabled Icon" type="string" />
<Option opt={options.bar.customModules.hyprsunset.onLabel} title="Enabled Label" type="string" />
<Option opt={options.bar.customModules.hyprsunset.offLabel} title="Disabled Label" type="string" />
<Option opt={options.bar.customModules.hyprsunset.label} title="Show Label" type="boolean" />
<Option opt={options.theme.bar.buttons.modules.hyprsunset.spacing} title="Spacing" type="string" />
<Option
opt={options.bar.customModules.hyprsunset.pollingInterval}
title="Polling Interval"
type="number"
min={100}
max={60 * 24 * 1000}
increment={1000}
/>
<Option opt={options.bar.customModules.hyprsunset.rightClick} title="Right Click" type="string" />
<Option opt={options.bar.customModules.hyprsunset.middleClick} title="Middle Click" type="string" />
<Option opt={options.bar.customModules.hyprsunset.scrollUp} title="Scroll Up" type="string" />
<Option opt={options.bar.customModules.hyprsunset.scrollDown} title="Scroll Down" type="string" />

{/* Hypridle Section */}
<Header title="Hypridle" />
<Option
opt={options.theme.bar.buttons.modules.hypridle.enableBorder}
title="Button Border"
type="boolean"
/>
<Option opt={options.bar.customModules.hypridle.onIcon} title="Enabled Icon" type="string" />
<Option opt={options.bar.customModules.hypridle.offIcon} title="Disabled Icon" type="string" />
<Option opt={options.bar.customModules.hypridle.onLabel} title="Enabled Label" type="string" />
<Option opt={options.bar.customModules.hypridle.offLabel} title="Disabled Label" type="string" />
<Option opt={options.bar.customModules.hypridle.label} title="Show Label" type="boolean" />
<Option opt={options.theme.bar.buttons.modules.hypridle.spacing} title="Spacing" type="string" />
<Option
opt={options.bar.customModules.hypridle.pollingInterval}
title="Polling Interval"
type="number"
min={100}
max={60 * 24 * 1000}
increment={1000}
/>
<Option opt={options.bar.customModules.hypridle.rightClick} title="Right Click" type="string" />
<Option opt={options.bar.customModules.hypridle.middleClick} title="Middle Click" type="string" />
<Option opt={options.bar.customModules.hypridle.scrollUp} title="Scroll Up" type="string" />
<Option opt={options.bar.customModules.hypridle.scrollDown} title="Scroll Down" type="string" />

{/* Power Section */}
<Header title="Power" />
<Option
opt={options.theme.bar.buttons.modules.power.enableBorder}
title="Button Border"
type="boolean"
/>
<Option opt={options.theme.bar.buttons.modules.power.spacing} title="Spacing" type="string" />
<Option opt={options.bar.customModules.power.icon} title="Power Button Icon" type="string" />
<Option opt={options.bar.customModules.power.leftClick} title="Left Click" type="string" />
<Option opt={options.bar.customModules.power.rightClick} title="Right Click" type="string" />
<Option opt={options.bar.customModules.power.middleClick} title="Middle Click" type="string" />
<Option opt={options.bar.customModules.power.scrollUp} title="Scroll Up" type="string" />
<Option opt={options.bar.customModules.power.scrollDown} title="Scroll Down" type="string" />
</box>
</scrollable>
);
Expand Down
Loading

0 comments on commit 27f2df3

Please sign in to comment.