Skip to content

Commit

Permalink
Add mouse actions (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
Morwdan authored Aug 13, 2024
1 parent b3b9d4c commit 4dcc829
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions modules/workspace.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ let
type = 6;
};

mouseActions = {
applicationLauncher = "org.kde.applauncher";
contextMenu = "org.kde.contextmenu";
paste = "org.kde.paste";
switchActivity = "switchactivity";
switchVirtualDesktop = "org.kde.switchdesktop";
switchWindow = "switchwindow";
};

mouseActionNamesEnum = lib.types.enum (builtins.attrNames mouseActions);

anyThemeSet = (cfg.workspace.theme != null ||
cfg.workspace.colorScheme != null ||
(cfg.workspace.cursor != null && cfg.workspace.cursor.theme != null) ||
Expand All @@ -44,6 +55,9 @@ let
in
recurse cfg.workspace.desktop.icons;

# Becomes true if any option under "cfg.workspace.desktop.mouseActions" is set to something other than null.
anyDesktopMouseActionsSet = lib.any (v: v != null) (builtins.attrValues cfg.workspace.desktop.mouseActions);

splashScreenEngineDetect = theme: (if (theme == "None") then "none" else "KSplashQML");
in
{
Expand Down Expand Up @@ -305,6 +319,40 @@ in
'';
};
};

mouseActions = {
leftClick = lib.mkOption {
type = lib.types.nullOr mouseActionNamesEnum;
default = null;
example = "appLauncher";
description = "Action for a left click on the desktop.";
apply = value: if (value == null) then null else mouseActions.${value};
};

middleClick = lib.mkOption {
type = lib.types.nullOr mouseActionNamesEnum;
default = null;
example = "switchWindow";
description = "Action for a click on the desktop with the middle mouse button.";
apply = value: if (value == null) then null else mouseActions.${value};
};

rightClick = lib.mkOption {
type = lib.types.nullOr mouseActionNamesEnum;
default = null;
example = "contextMenu";
description = "Action for a right click on the desktop.";
apply = value: if (value == null) then null else mouseActions.${value};
};

verticalScroll = lib.mkOption {
type = lib.types.nullOr mouseActionNamesEnum;
default = null;
example = "switchVirtualDesktop";
description = "Action for scrolling (vertically) while hovering over the desktop.";
apply = value: if (value == null) then null else mouseActions.${value};
};
};
};
};

Expand Down Expand Up @@ -429,6 +477,22 @@ in
'';
priority = 3;
});

desktopScript."set_desktop_mouse_actions" = (lib.mkIf anyDesktopMouseActionsSet {
text = ''
// Mouse actions
let configFile = ConfigFile('plasma-org.kde.plasma.desktop-appletsrc');
configFile.group = 'ActionPlugins';
// References the section [ActionPlugins][0].
let actionPluginSubSection = ConfigFile(configFile, 0)
${stringIfNotNull cfg.workspace.desktop.mouseActions.leftClick ''actionPluginSubSection.writeEntry("LeftButton;NoModifier", "${cfg.workspace.desktop.mouseActions.leftClick}");''}
${stringIfNotNull cfg.workspace.desktop.mouseActions.middleClick ''actionPluginSubSection.writeEntry("MiddleButton;NoModifier", "${cfg.workspace.desktop.mouseActions.middleClick}");''}
${stringIfNotNull cfg.workspace.desktop.mouseActions.rightClick ''actionPluginSubSection.writeEntry("RightButton;NoModifier", "${cfg.workspace.desktop.mouseActions.rightClick}");''}
${stringIfNotNull cfg.workspace.desktop.mouseActions.verticalScroll ''actionPluginSubSection.writeEntry("wheel:Vertical;NoModifier", "${cfg.workspace.desktop.mouseActions.verticalScroll}");''}
'';
priority = 3;
restartServices = [ "plasma-plasmashell" ];
});
};

# The wallpaper configuration can be found in panels.nix due to wallpaper
Expand Down

0 comments on commit 4dcc829

Please sign in to comment.