From 9627640e6b9c4ad8f8453fe7fd555cd43b0417fa Mon Sep 17 00:00:00 2001 From: nx-smul Date: Sat, 8 Feb 2025 13:00:47 +0600 Subject: [PATCH 1/6] added module Hyprland gamemode --- .config/ags/modules/sideright/quicktoggles.js | 28 +++++++++++++++++++ .config/ags/modules/sideright/sideright.js | 2 ++ 2 files changed, 30 insertions(+) diff --git a/.config/ags/modules/sideright/quicktoggles.js b/.config/ags/modules/sideright/quicktoggles.js index 3aabca64..9f3b3c6d 100644 --- a/.config/ags/modules/sideright/quicktoggles.js +++ b/.config/ags/modules/sideright/quicktoggles.js @@ -203,6 +203,34 @@ export const ModuleRawInput = async (props = {}) => { }; } +export const ModuleGameMode = async (props = {}) => { + try { + const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default; + return Widget.Button({ + className: 'txt-small sidebar-iconbutton', + tooltipText: getString('Hyprland Game Mode'), + onClicked: (button) => { + Hyprland.messageAsync('j/getoption animations:enabled') + .then((output) => { + const value = JSON.parse(output)["int"]; + if (value == 1) { + execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 0; keyword decoration:shadow:enabled 0; keyword decoration:blur:enabled 0; keyword general:gaps_in 0; keyword general:gaps_out 0; keyword general:border_size 1; keyword decoration:rounding 0; keyword general:allow_tearing 0" & hyprctl reload`]).catch(print); + button.toggleClassName('sidebar-button-active', false); + } else { + execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 1; keyword general:allow_tearing 1" & hyprctl reload`]).catch(print); + button.toggleClassName('sidebar-button-active', true); + } + }) + }, + child: MaterialIcon('gamepad', 'norm'), + setup: setupCursorHover, + ...props, + }) + } catch { + return null; + }; +} + export const ModuleIdleInhibitor = (props = {}) => Widget.Button({ // TODO: Make this work attribute: { enabled: false, diff --git a/.config/ags/modules/sideright/sideright.js b/.config/ags/modules/sideright/sideright.js index aa922b0a..02b8f287 100644 --- a/.config/ags/modules/sideright/sideright.js +++ b/.config/ags/modules/sideright/sideright.js @@ -13,6 +13,7 @@ import { ModuleSettingsIcon, ModulePowerIcon, ModuleRawInput, + ModuleGameMode, ModuleCloudflareWarp } from "./quicktoggles.js"; import ModuleNotificationList from "./centermodules/notificationlist.js"; @@ -125,6 +126,7 @@ const togglesBox = Widget.Box({ // await HyprToggleIcon('touchpad_mouse', 'No touchpad while typing', 'input:touchpad:disable_while_typing', {}), await ModuleNightLight(), await ModuleInvertColors(), + await ModuleGameMode(), ModuleIdleInhibitor(), await ModuleCloudflareWarp(), ] From 72d488faf811729c6231b6119243283aabd34734 Mon Sep 17 00:00:00 2001 From: Shimul <68707319+nx-smul@users.noreply.github.com> Date: Sat, 8 Feb 2025 17:49:20 +0600 Subject: [PATCH 2/6] fixed tearing ooption --- .config/ags/modules/sideright/quicktoggles.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/ags/modules/sideright/quicktoggles.js b/.config/ags/modules/sideright/quicktoggles.js index 9f3b3c6d..8bd79b1c 100644 --- a/.config/ags/modules/sideright/quicktoggles.js +++ b/.config/ags/modules/sideright/quicktoggles.js @@ -214,10 +214,10 @@ export const ModuleGameMode = async (props = {}) => { .then((output) => { const value = JSON.parse(output)["int"]; if (value == 1) { - execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 0; keyword decoration:shadow:enabled 0; keyword decoration:blur:enabled 0; keyword general:gaps_in 0; keyword general:gaps_out 0; keyword general:border_size 1; keyword decoration:rounding 0; keyword general:allow_tearing 0" & hyprctl reload`]).catch(print); + execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 0; keyword decoration:shadow:enabled 0; keyword decoration:blur:enabled 0; keyword general:gaps_in 0; keyword general:gaps_out 0; keyword general:border_size 1; keyword decoration:rounding 0; keyword general:allow_tearing 1" & hyprctl reload`]).catch(print); button.toggleClassName('sidebar-button-active', false); } else { - execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 1; keyword general:allow_tearing 1" & hyprctl reload`]).catch(print); + execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 1; keyword general:allow_tearing 0" & hyprctl reload`]).catch(print); button.toggleClassName('sidebar-button-active', true); } }) From a94389ed69d836584593da591acd1300c0d0782c Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:04:29 +0100 Subject: [PATCH 3/6] user options: add quick toggles order --- .../modules/.configuration/user_options.js | 3 +++ .config/ags/modules/sideright/sideright.js | 24 ++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.config/ags/modules/.configuration/user_options.js b/.config/ags/modules/.configuration/user_options.js index e56e7628..89baf946 100644 --- a/.config/ags/modules/.configuration/user_options.js +++ b/.config/ags/modules/.configuration/user_options.js @@ -115,6 +115,9 @@ let configOptions = { 'order': ["gemini", "gpt", "waifu", "booru"], } }, + 'quickToggles': { + 'order': ["wifi", "bluetooth", "nightlight", "gamemode", "idleinhibitor", "cloudflarewarp"], + } }, 'search': { 'enableFeatures': { diff --git a/.config/ags/modules/sideright/sideright.js b/.config/ags/modules/sideright/sideright.js index 02b8f287..50258571 100644 --- a/.config/ags/modules/sideright/sideright.js +++ b/.config/ags/modules/sideright/sideright.js @@ -27,6 +27,18 @@ import { MaterialIcon } from '../.commonwidgets/materialicon.js'; import { ExpandingIconTabContainer } from '../.commonwidgets/tabcontainer.js'; import { checkKeybind } from '../.widgetutils/keybind.js'; +const QUICK_TOGGLES = { + 'wifi': ToggleIconWifi(), + 'bluetooth': ToggleIconBluetooth(), + 'rawinput': await ModuleRawInput(), + 'touchpad': await HyprToggleIcon('touchpad_mouse', 'No touchpad while typing', 'input:touchpad:disable_while_typing', {}), + 'nightlight': await ModuleNightLight(), + 'invertcolors': await ModuleInvertColors(), + 'gamemode': await ModuleGameMode(), + 'idleinhibitor': ModuleIdleInhibitor(), + 'cloudflarewarp': await ModuleCloudflareWarp(), +} + const centerWidgets = [ { name: getString('Notifications'), @@ -119,17 +131,7 @@ const timeRow = Box({ const togglesBox = Widget.Box({ hpack: 'center', className: 'sidebar-togglesbox spacing-h-5', - children: [ - ToggleIconWifi(), - ToggleIconBluetooth(), - // await ModuleRawInput(), - // await HyprToggleIcon('touchpad_mouse', 'No touchpad while typing', 'input:touchpad:disable_while_typing', {}), - await ModuleNightLight(), - await ModuleInvertColors(), - await ModuleGameMode(), - ModuleIdleInhibitor(), - await ModuleCloudflareWarp(), - ] + children: userOptions.sidebar.quickToggles.order.map(toggle => QUICK_TOGGLES[toggle]) }) export const sidebarOptionsStack = ExpandingIconTabContainer({ From ebb243f2a9749807a74ccf8bb9a56ccb986f8ae1 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:09:50 +0100 Subject: [PATCH 4/6] game mode toggle: fix reversed button appearance --- .config/ags/modules/sideright/quicktoggles.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.config/ags/modules/sideright/quicktoggles.js b/.config/ags/modules/sideright/quicktoggles.js index 8bd79b1c..f7f309a3 100644 --- a/.config/ags/modules/sideright/quicktoggles.js +++ b/.config/ags/modules/sideright/quicktoggles.js @@ -212,14 +212,13 @@ export const ModuleGameMode = async (props = {}) => { onClicked: (button) => { Hyprland.messageAsync('j/getoption animations:enabled') .then((output) => { - const value = JSON.parse(output)["int"]; - if (value == 1) { + const enabled = JSON.parse(output)["int"] === 1; + if (enabled) { execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 0; keyword decoration:shadow:enabled 0; keyword decoration:blur:enabled 0; keyword general:gaps_in 0; keyword general:gaps_out 0; keyword general:border_size 1; keyword decoration:rounding 0; keyword general:allow_tearing 1" & hyprctl reload`]).catch(print); - button.toggleClassName('sidebar-button-active', false); } else { execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 1; keyword general:allow_tearing 0" & hyprctl reload`]).catch(print); - button.toggleClassName('sidebar-button-active', true); } + button.toggleClassName('sidebar-button-active', enabled); }) }, child: MaterialIcon('gamepad', 'norm'), From 9aefc98201c05e6ea087e44875f1d3cbcfd8954a Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:12:43 +0100 Subject: [PATCH 5/6] make game mode toggle work more consistently --- .config/ags/modules/sideright/quicktoggles.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/ags/modules/sideright/quicktoggles.js b/.config/ags/modules/sideright/quicktoggles.js index f7f309a3..99671907 100644 --- a/.config/ags/modules/sideright/quicktoggles.js +++ b/.config/ags/modules/sideright/quicktoggles.js @@ -214,9 +214,9 @@ export const ModuleGameMode = async (props = {}) => { .then((output) => { const enabled = JSON.parse(output)["int"] === 1; if (enabled) { - execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 0; keyword decoration:shadow:enabled 0; keyword decoration:blur:enabled 0; keyword general:gaps_in 0; keyword general:gaps_out 0; keyword general:border_size 1; keyword decoration:rounding 0; keyword general:allow_tearing 1" & hyprctl reload`]).catch(print); + execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 0; keyword decoration:shadow:enabled 0; keyword decoration:blur:enabled 0; keyword general:gaps_in 0; keyword general:gaps_out 0; keyword general:border_size 1; keyword decoration:rounding 0; keyword general:allow_tearing 1"`]).catch(print); } else { - execAsync(['bash', '-c', `hyprctl --batch "keyword animations:enabled 1; keyword general:allow_tearing 0" & hyprctl reload`]).catch(print); + execAsync(['bash', '-c', `hyprctl reload`]).catch(print); } button.toggleClassName('sidebar-button-active', enabled); }) From cf7a89afde8a0e0f23dfd86157fc1520c890b7a5 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:36:07 +0100 Subject: [PATCH 6/6] game mode toggle: run hyprctl directly instead of relying on ags moar consistency --- .config/ags/modules/sideright/quicktoggles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/ags/modules/sideright/quicktoggles.js b/.config/ags/modules/sideright/quicktoggles.js index 99671907..cf806ee1 100644 --- a/.config/ags/modules/sideright/quicktoggles.js +++ b/.config/ags/modules/sideright/quicktoggles.js @@ -210,7 +210,7 @@ export const ModuleGameMode = async (props = {}) => { className: 'txt-small sidebar-iconbutton', tooltipText: getString('Hyprland Game Mode'), onClicked: (button) => { - Hyprland.messageAsync('j/getoption animations:enabled') + Utils.execAsync(`hyprctl -j getoption animations:enabled`) .then((output) => { const enabled = JSON.parse(output)["int"] === 1; if (enabled) {