1 Commits
master ... v1.3

Author SHA1 Message Date
1031d5590b Feature: query current windowing mode 2026-01-06 16:26:03 +01:00
22 changed files with 131 additions and 386 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,3 @@
.cache/ .cache/
build/ build/
.vscode/ .vscode/
result

View File

@@ -1,45 +1,9 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.10.0)
project(hyprland-toggle-tiling VERSION 0.1.0 LANGUAGES C CXX)
project(hyprland-toggle-tiling
VERSION 1.4.2
LANGUAGES CXX
)
include(GNUInstallDirs)
include(FetchContent) include(FetchContent)
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz)
# -------------------------------------------------- FetchContent_MakeAvailable(json)
# Dependency handling
# --------------------------------------------------
option(USE_SYSTEM_JSON
"Use system-installed nlohmann_json instead of fetching"
OFF
)
if(USE_SYSTEM_JSON)
find_package(nlohmann_json CONFIG REQUIRED)
else()
# Try system package first silently
find_package(nlohmann_json CONFIG QUIET)
if(NOT nlohmann_json_FOUND)
message(STATUS "nlohmann_json not found, fetching from GitHub")
FetchContent_Declare(
nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.12.0/json.tar.xz
)
FetchContent_MakeAvailable(nlohmann_json)
else()
message(STATUS "Using system nlohmann_json")
endif()
endif()
# --------------------------------------------------
# Executable
# --------------------------------------------------
add_executable(htt add_executable(htt
src/main.cpp src/main.cpp
@@ -48,22 +12,6 @@ add_executable(htt
src/ShellService.cpp src/ShellService.cpp
src/FileService.cpp src/FileService.cpp
src/WindowRule.cpp src/WindowRule.cpp
src/Client.cpp src/Client.cpp)
) target_link_libraries(htt PRIVATE nlohmann_json::nlohmann_json)
target_include_directories(htt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(htt PRIVATE cxx_std_17)
target_link_libraries(htt
PRIVATE
nlohmann_json::nlohmann_json
)
target_include_directories(htt PRIVATE ${PROJECT_SOURCE_DIR}/src)
# --------------------------------------------------
# Install
# --------------------------------------------------
install(TARGETS htt
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -30,7 +30,6 @@ Check out [the demo](https://typofelho.ddns.net/TypoMustakes/hyprland-toggle-til
Switch to floating mode again and newly opened windows will be in floating mode. Switch to floating mode again and newly opened windows will be in floating mode.
- Floating/tiling window rules are isolated between workspaces. You can set one workspace to be floating, and all the rest to tiling for example. - Floating/tiling window rules are isolated between workspaces. You can set one workspace to be floating, and all the rest to tiling for example.
- Returns applied rule for the current workspace. Useful for scripting. - Returns applied rule for the current workspace. Useful for scripting.
- Moving a window from a tiling workspace to a floating one changes the float state of the window to respect the new workspace.
- Useful for workflows that require both tiling and floating window management. - Useful for workflows that require both tiling and floating window management.
- Lightweight and easy to integrate with your Hyprland setup. - Lightweight and easy to integrate with your Hyprland setup.
@@ -42,34 +41,6 @@ You have a few options of obtainting the program.
You may install this program [from the AUR.](https://aur.archlinux.org/packages/hyprland-toggle-tiling-git) You may install this program [from the AUR.](https://aur.archlinux.org/packages/hyprland-toggle-tiling-git)
### Nix Flake (for Nix users)
This project provides a Nix flake for reproducible builds and easy installation.
#### Build the package
```shell
nix build git+ssh://gitea@typofelho.ddns.net/TypoMustakes/hyprland-toggle-tiling.git
```
The binary will be at `./result/bin/htt`.
#### Add to Home Manager
1. Add the flake as an input:
```shell
inputs.htt.url = "git+ssh://gitea@typofelho.ddns.net/TypoMustakes/hyprland-toggle-tiling.git";
```
2. Then include it in your configuration:
```shell
home.packages = [
inputs.htt.packages.${pkgs.system}.default
];
```
### Download the release ### Download the release
You can also [download the release binary.](https://typofelho.ddns.net/TypoMustakes/hyprland-toggle-tiling/releases) You can also [download the release binary.](https://typofelho.ddns.net/TypoMustakes/hyprland-toggle-tiling/releases)
@@ -105,7 +76,7 @@ or go nuts and...
# Usage # Usage
```shell ```shell
./htt <config-file-path> (flags) ./htt <config-file-path> (-q)
``` ```
- `-q`: Print the rule applied on the current workspace to STDOUT, but don't change anything. If there isn't an active rule for the current workspace, it returns a tiling rule. The returned string is a valid Hyprland window rule configuration line, like so: - `-q`: Print the rule applied on the current workspace to STDOUT, but don't change anything. If there isn't an active rule for the current workspace, it returns a tiling rule. The returned string is a valid Hyprland window rule configuration line, like so:
@@ -115,11 +86,6 @@ $ ./htt ~/.cache/htt/rules -q
windowrule = tile on, match:workspace 2 windowrule = tile on, match:workspace 2
``` ```
Potential applications for this are mainly scripts, like my waybar module here:
![wayland module showcase](https://typofelho.ddns.net/TypoMustakes/hyprland-toggle-tiling/raw/branch/master/assets/waybar_module.gif)
- `-m [integer]`: Move currently active window to specified workspace. Upon moving, the window will adapt to the windowing mode of the new workspace. Doesn't work with `-q`. See ![the 1.4 changelog](https://typofelho.ddns.net/TypoMustakes/hyprland-toggle-tiling/releases/tag/v1.4) for details.
- If the specified configuration file does not exist, it will be created. - If the specified configuration file does not exist, it will be created.
- If the configuration contains existing rules, this should still work, but your existing configuration will probably get a bit messy, syntax-wise. I advise against it. - If the configuration contains existing rules, this should still work, but your existing configuration will probably get a bit messy, syntax-wise. I advise against it.
@@ -135,37 +101,5 @@ Potential applications for this are mainly scripts, like my waybar module here:
bind = $mod + t, exec, /path/to/htt <config-file-path> bind = $mod + t, exec, /path/to/htt <config-file-path>
``` ```
3. If you want windows to respect workspaces' rules after moving them to another workspace (see ![the 1.4 changelog](https://typofelho.ddns.net/TypoMustakes/hyprland-toggle-tiling/releases/tag/v1.4) for details), you might want to tell HTT to move your windows instead of telling Hyprland. Or not. Do whatever you want.
On the default configuration, this would mean changing this:
```sh
bind = $mainMod SHIFT, 1, movetoworkspace, 1
bind = $mainMod SHIFT, 2, movetoworkspace, 2
bind = $mainMod SHIFT, 3, movetoworkspace, 3
bind = $mainMod SHIFT, 4, movetoworkspace, 4
bind = $mainMod SHIFT, 5, movetoworkspace, 5
bind = $mainMod SHIFT, 6, movetoworkspace, 6
bind = $mainMod SHIFT, 7, movetoworkspace, 7
bind = $mainMod SHIFT, 8, movetoworkspace, 8
bind = $mainMod SHIFT, 9, movetoworkspace, 9
bind = $mainMod SHIFT, 0, movetoworkspace, 10
```
to this:
```sh
bind = $mainMod SHIFT, 1, exec, htt [your htt config file] -m 1
bind = $mainMod SHIFT, 2, exec, htt [your htt config file] -m 2
bind = $mainMod SHIFT, 3, exec, htt [your htt config file] -m 3
bind = $mainMod SHIFT, 4, exec, htt [your htt config file] -m 4
bind = $mainMod SHIFT, 5, exec, htt [your htt config file] -m 5
bind = $mainMod SHIFT, 6, exec, htt [your htt config file] -m 6
bind = $mainMod SHIFT, 7, exec, htt [your htt config file] -m 7
bind = $mainMod SHIFT, 8, exec, htt [your htt config file] -m 8
bind = $mainMod SHIFT, 9, exec, htt [your htt config file] -m 9
bind = $mainMod SHIFT, 0, exec, htt [your htt config file] -m 10
```
... in your configuration.
Otherwise, just use `exec, htt [your htt config file] -m [workspace ID]` wherever you used `movetoworkspace [workspace ID]` before.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

View File

@@ -1,37 +0,0 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.stdenv.mkDerivation rec {
pname = "hyprland-toggle-tiling";
version = "1.4.2";
src = pkgs.fetchFromGitHub {
owner = "TypoMustakes";
repo = "hyprland-toggle-tiling";
rev = "v${version}";
sha256 = "sha256-5mI5WiPjSU+/MgvTPNvE6Ck/WBnidaFwW9/xeL7MMWE=";
};
nativeBuildInputs = [
pkgs.cmake
pkgs.pkg-config
];
buildInputs = [
pkgs.hyprland
pkgs.nlohmann_json
];
cmakeFlags = [
"-DUSE_SYSTEM_JSON=ON"
];
cmakeBuildType = "Release";
meta = with pkgs.lib; {
description = "Toggle tiling and floating modes in Hyprland globally.";
homepage = "https://github.com/TypoMustakes/hyprland-toggle-tiling";
license = licenses.gpl3Only;
platforms = platforms.linux;
mainProgram = "htt";
};
}

27
flake.lock generated
View File

@@ -1,27 +0,0 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1775710090,
"narHash": "sha256-ar3rofg+awPB8QXDaFJhJ2jJhu+KqN/PRCXeyuXR76E=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "4c1018dae018162ec878d42fec712642d214fdfa",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

View File

@@ -1,20 +0,0 @@
{
description = "hyprland-toggle-tiling";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
{
packages.${system}.default = pkgs.callPackage ./default.nix {};
apps.${system}.default = {
type = "app";
program = "${self.packages.${system}.default}/bin/htt";
};
};
}

View File

@@ -23,6 +23,7 @@ class Client {
std::array<int, 2> size; std::array<int, 2> size;
WorkspaceSignature workspace; WorkspaceSignature workspace;
bool floating; bool floating;
bool pseudo;
int monitor; int monitor;
std::string className; std::string className;
std::string title; std::string title;
@@ -33,7 +34,6 @@ class Client {
bool pinned; bool pinned;
int fullscreen; int fullscreen;
int fullscreenClient; int fullscreenClient;
bool overFullscreen;
std::string swallowing; std::string swallowing;
int focusHistory; int focusHistory;
bool inhibitingIdle; bool inhibitingIdle;

View File

@@ -2,36 +2,27 @@
#define HYPRLAND_SERVICE_H #define HYPRLAND_SERVICE_H
#include <list> #include <list>
#include "Workspace.hpp" #include "Workspace.h"
#include "Client.hpp" #include "Client.h"
#include "WindowRule.hpp" #include "WindowRule.h"
class HyprlandService { class HyprlandService {
private: private:
static std::string configFilePath; static std::string configFilePath;
public:
static void setConfigFilePath(std::string);
static std::string getConfigFilePath(); static std::string getConfigFilePath();
static std::list<Workspace> getWorkspaces();
static std::optional<Workspace> getWorkspace(int);
static Workspace getCurrentWorkspace(); static Workspace getCurrentWorkspace();
static std::list<Client> getClients(); static std::list<Client> getClients();
static std::list<Client> getClientsOnActiveWorkspace(); static std::list<Client> getClientsOnActiveWorkspace();
static Client getActiveClient();
static bool isFloatingRulePresent(int);
static bool isFloatingRulePresent(Workspace);
static std::list<WindowRule> getWindowRules(); static std::list<WindowRule> getWindowRules();
static std::optional<WindowRule> findConflictingRule(WindowRule); static std::optional<WindowRule> findConflictingRule(WindowRule);
static void setFloatingRule(bool); static void setFloatingRule(bool);
static void removeRule(WindowRule); static void removeRule(WindowRule);
static void setClientFloating(Client&);
static void setClientFloating(Client); static void setClientTiled(Client&);
static void setClientTiled(Client); static void toggleClientFloating(Client&);
public: static bool isFloatingRulePresent();
static void toggleFloating();
static void moveToWorkspace(int);
static void setConfigFilePath(std::string);
static WindowRule getActiveWorkspaceRule(); static WindowRule getActiveWorkspaceRule();
}; };
#endif #endif

9
include/Macros.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef MACROS_H
#define MACROS_H
#define HYPRCTL_BINARY "/usr/bin/hyprctl"
#define NULL_PATH "/dev/null"
#define ECHO_PATH "/usr/bin/echo"
#define CAT_PATH "/usr/bin/cat"
#endif

View File

@@ -1,9 +0,0 @@
#ifndef MACROS_H
#define MACROS_H
#define HYPRCTL_BINARY "hyprctl"
#define NULL_PATH "/dev/null"
#define ECHO_PATH "echo"
#define CAT_PATH "cat"
#endif

View File

@@ -1,4 +1,4 @@
#include "../include/Client.hpp" #include "../include/Client.h"
void from_json(const json& j, WorkspaceSignature& ws) { void from_json(const json& j, WorkspaceSignature& ws) {
j.at("id").get_to(ws.id); j.at("id").get_to(ws.id);
@@ -12,6 +12,7 @@ void from_json(const json& j, Client& client) {
j.at("size").get_to(client.size); j.at("size").get_to(client.size);
j.at("workspace").get_to(client.workspace); j.at("workspace").get_to(client.workspace);
j.at("floating").get_to(client.floating); j.at("floating").get_to(client.floating);
j.at("pseudo").get_to(client.pseudo);
j.at("monitor").get_to(client.monitor); j.at("monitor").get_to(client.monitor);
j.at("class").get_to(client.className); // Maps "class" JSON field to className j.at("class").get_to(client.className); // Maps "class" JSON field to className
j.at("title").get_to(client.title); j.at("title").get_to(client.title);
@@ -22,7 +23,6 @@ void from_json(const json& j, Client& client) {
j.at("pinned").get_to(client.pinned); j.at("pinned").get_to(client.pinned);
j.at("fullscreen").get_to(client.fullscreen); j.at("fullscreen").get_to(client.fullscreen);
j.at("fullscreenClient").get_to(client.fullscreenClient); j.at("fullscreenClient").get_to(client.fullscreenClient);
j.at("overFullscreen").get_to(client.overFullscreen);
j.at("swallowing").get_to(client.swallowing); j.at("swallowing").get_to(client.swallowing);
j.at("focusHistoryID").get_to(client.focusHistory); j.at("focusHistoryID").get_to(client.focusHistory);
j.at("inhibitingIdle").get_to(client.inhibitingIdle); j.at("inhibitingIdle").get_to(client.inhibitingIdle);

View File

@@ -1,8 +1,8 @@
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include "../include/FileService.hpp" #include "../include/FileService.h"
#include "../include/Macros.hpp" #include "../include/Macros.h"
#include "../include/ShellService.hpp" #include "../include/ShellService.h"
bool FileService::doesNonEmptyFileExist(std::string path) { bool FileService::doesNonEmptyFileExist(std::string path) {
std::ifstream file(path); std::ifstream file(path);

View File

@@ -1,10 +1,8 @@
#include "../include/HyprlandService.hpp"
#include "../include/FileService.hpp"
#include "../include/Macros.hpp"
#include "../include/ShellService.hpp"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <optional> #include "../include/HyprlandService.h"
#include <string> #include "../include/ShellService.h"
#include "../include/Macros.h"
#include "../include/FileService.h"
using json = nlohmann::json; using json = nlohmann::json;
@@ -20,37 +18,14 @@ void HyprlandService::setConfigFilePath(std::string path) {
configFilePath = path; configFilePath = path;
}; };
std::string HyprlandService::getConfigFilePath() { return configFilePath; }; std::string HyprlandService::getConfigFilePath() {
return configFilePath;
std::list<Workspace> HyprlandService::getWorkspaces() {
json j = json::parse(ShellService::exec(HYPRCTL_BINARY " workspaces -j"));
return j.get<std::list<Workspace>>();
}
std::optional<Workspace> HyprlandService::getWorkspace(int id) {
std::list<Workspace> workspaces = getWorkspaces();
for (auto it = workspaces.begin(); it != workspaces.end();) {
if (it->id == id) {
return *it;
} else {
++it;
}
}
return std::nullopt;
}
Workspace HyprlandService::getCurrentWorkspace() {
json j =
json::parse(ShellService::exec(HYPRCTL_BINARY " activeworkspace -j"));
return j.get<Workspace>();
}; };
Client HyprlandService::getActiveClient() { Workspace HyprlandService::getCurrentWorkspace() {
json j = json::parse(ShellService::exec(HYPRCTL_BINARY " activewindow -j")); json j = json::parse(ShellService::exec(HYPRCTL_BINARY " activeworkspace -j"));
return j.get<Client>(); return j.get<Workspace>();
} };
std::list<Client> HyprlandService::getClients() { std::list<Client> HyprlandService::getClients() {
json j = json::parse(ShellService::exec(HYPRCTL_BINARY " clients -j")); json j = json::parse(ShellService::exec(HYPRCTL_BINARY " clients -j"));
@@ -82,18 +57,20 @@ std::list<WindowRule> HyprlandService::getWindowRules() {
return rules; return rules;
}; };
void HyprlandService::setClientFloating(Client c) { void HyprlandService::setClientFloating(Client& c) {
ShellService::exec(HYPRCTL_BINARY " dispatch setfloating address:" + ShellService::exec(HYPRCTL_BINARY " dispatch setfloating address:" + c.address);
c.address);
}; };
void HyprlandService::setClientTiled(Client c) { void HyprlandService::setClientTiled(Client& c) {
ShellService::exec(HYPRCTL_BINARY " dispatch settiled address:" + c.address); ShellService::exec(HYPRCTL_BINARY " dispatch settiled address:" + c.address);
} }
// on = true -> creates a window rule to ENABLE floating mode for currently void HyprlandService::toggleClientFloating(Client& c) {
// active workspace on = false -> creates a window rule to DISABLE floating mode ShellService::exec(HYPRCTL_BINARY " dispatch togglefloating address:" + c.address);
// for currently active workspace };
//on = true -> creates a window rule to ENABLE floating mode for currently active workspace
//on = false -> creates a window rule to DISABLE floating mode for currently active workspace
void HyprlandService::setFloatingRule(bool on) { void HyprlandService::setFloatingRule(bool on) {
WindowRule rule {.tile = !on, .workspaceID = getCurrentWorkspace().id}; WindowRule rule {.tile = !on, .workspaceID = getCurrentWorkspace().id};
auto conflictingRule = findConflictingRule(rule); auto conflictingRule = findConflictingRule(rule);
@@ -101,16 +78,19 @@ void HyprlandService::setFloatingRule(bool on) {
removeRule(conflictingRule.value()); removeRule(conflictingRule.value());
} }
FileService::appendToFile(getConfigFilePath(), rule.toString()); FileService::appendToFile(
getConfigFilePath(),
rule.toString()
);
}; };
std::optional<WindowRule> std::optional<WindowRule> HyprlandService::findConflictingRule(WindowRule subject) {
HyprlandService::findConflictingRule(WindowRule subject) {
std::list<WindowRule> rules = getWindowRules(); std::list<WindowRule> rules = getWindowRules();
int id = getCurrentWorkspace().id; int id = getCurrentWorkspace().id;
for (auto& rule : rules) { for (auto& rule : rules) {
if (rule.tile == !subject.tile && rule.workspaceID == subject.workspaceID) { if (rule.tile == !subject.tile && rule.workspaceID == subject.workspaceID)
{
return rule; return rule;
} }
} }
@@ -124,7 +104,8 @@ void HyprlandService::removeRule(WindowRule rule) {
int foundIndex = -1; int foundIndex = -1;
for (auto& it : rules) { for (auto& it : rules) {
if (it.toString() == rule.toString()) { if (it.toString() == rule.toString())
{
foundIndex = index; foundIndex = index;
break; break;
} }
@@ -132,26 +113,27 @@ void HyprlandService::removeRule(WindowRule rule) {
} }
if (foundIndex != -1) { if (foundIndex != -1) {
FileService::deleteNthLine(getConfigFilePath(), foundIndex); FileService::deleteNthLine(
getConfigFilePath(),
foundIndex
);
} }
//else: rule not found, do nothing //else: rule not found, do nothing
} }
bool HyprlandService::isFloatingRulePresent(int workspaceId) { bool HyprlandService::isFloatingRulePresent() {
//Checks if there's a valid window rule in place that enables floating mode for the currently active workspace
std::list<WindowRule> rules = getWindowRules(); std::list<WindowRule> rules = getWindowRules();
int id = getCurrentWorkspace().id;
for (auto& rule : rules) { for (auto& rule : rules) {
if (rule.workspaceID == workspaceId && rule.tile == false) { if (rule.workspaceID == id && rule.tile == false) {
return true; return true;
} }
} }
return false; return false;
}
bool HyprlandService::isFloatingRulePresent(Workspace workspace) {
return isFloatingRulePresent(workspace.id);
}; };
WindowRule HyprlandService::getActiveWorkspaceRule() { WindowRule HyprlandService::getActiveWorkspaceRule() {
@@ -167,28 +149,3 @@ WindowRule HyprlandService::getActiveWorkspaceRule() {
//If no rule is found, return a default rule (tiled) //If no rule is found, return a default rule (tiled)
return WindowRule {.tile = true, .workspaceID = id}; return WindowRule {.tile = true, .workspaceID = id};
}; };
void HyprlandService::moveToWorkspace(int workspaceId) {
if (isFloatingRulePresent(workspaceId)) {
setClientFloating(getActiveClient());
} else {
setClientTiled(getActiveClient());
}
ShellService::exec(HYPRCTL_BINARY " dispatch movetoworkspace " +
std::to_string(workspaceId));
}
void HyprlandService::toggleFloating() {
if (isFloatingRulePresent(getCurrentWorkspace())) {
for (auto &c : getClientsOnActiveWorkspace()) {
setClientTiled(c);
}
setFloatingRule(false);
} else {
for (auto &c : getClientsOnActiveWorkspace()) {
setClientFloating(c);
}
setFloatingRule(true);
}
}

View File

@@ -1,4 +1,4 @@
#include "../include/ShellService.hpp" #include "../include/ShellService.h"
#include <pwd.h> #include <pwd.h>
#include <unistd.h> #include <unistd.h>
@@ -23,16 +23,15 @@ std::string ShellService::exec(const std::string &command) {
return result; return result;
}; };
std::string ShellService::getHomePath() { std::string ShellService::getHomePath()
{
char* home = getenv("HOME"); char* home = getenv("HOME");
if (home && *home) { if (home && *home) {
return std::string(home) + std::string("/"); return std::string(home);
} }
// Fallback: try to get home directory from passwd if HOME is not set // Fallback: try to get home directory from passwd if HOME is not set
// This assumes that the 'htt' process is ran with the user as the process // This assumes that the 'htt' process is ran with the user as the process owner. Should it be run with systemd or some other wonky method, it will behave unexpectedly
// owner. Should it be run with systemd or some other wonky method, it will
// behave unexpectedly
struct passwd* pw = getpwuid(getuid()); struct passwd* pw = getpwuid(getuid());
if (pw && pw->pw_dir) { if (pw && pw->pw_dir) {
return std::string(pw->pw_dir); return std::string(pw->pw_dir);

View File

@@ -1,5 +1,5 @@
#include <algorithm> #include <algorithm>
#include "../include/WindowRule.hpp" #include "../include/WindowRule.h"
std::string WindowRule::toString() { std::string WindowRule::toString() {
std::string mode = this->tile ? "tile on" : "float on"; std::string mode = this->tile ? "tile on" : "float on";

View File

@@ -1,4 +1,4 @@
#include "../include/Workspace.hpp" #include "../include/Workspace.h"
void from_json(const nlohmann::json &j, Workspace &w) { void from_json(const nlohmann::json &j, Workspace &w) {
j.at("id").get_to(w.id); j.at("id").get_to(w.id);

View File

@@ -1,36 +1,37 @@
#include <iostream> #include <iostream>
#include <stdexcept> #include "../include/HyprlandService.h"
#include "../include/HyprlandService.hpp"
void help(char* execPath) { void help(char* execPath) {
std::cerr << "Usage: " << execPath << " <config_file_path> (flags)\n\n"; std::cerr << "Usage: " << execPath << " <config_file_path> (-q)\n\n";
std::cerr << "Flags:\n\n"; std::cerr << "-q:\tQuery current windowing mode, don't change anything.\n\tReturns Hyprland window rule active on current workspace.\n\tIf no rule is active, returns a default tiled rule.\n";
std::cerr << "-q:\t\tQuery current windowing mode, don't change anything.\n\t\tReturns Hyprland window rule active on current workspace.\n\t\tIf no rule is active, returns a default tiled rule.\n\n";
std::cerr << "-m [integer]:\tMove currently active window to specified workspace.\n\t\tUpon moving, the window will adapt to the windowing mode of the new workspace.\n\t\tDoesn't work with -q.\n";
exit(1); exit(1);
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
if (argc >= 2) { if (argc < 2) {
help(argv[0]);
}
HyprlandService::setConfigFilePath(argv[1]); HyprlandService::setConfigFilePath(argv[1]);
if (argc == 2) { if (argc == 3 && argv[2] == std::string("-q")) {
HyprlandService::toggleFloating(); WindowRule rule = HyprlandService::getActiveWorkspaceRule();
std::cout << rule.toString() << std::endl;
} }
else if (argc == 3 && argv[2] == std::string("-q")) { else if (argc == 2) {
std::cout << HyprlandService::getActiveWorkspaceRule().toString() << std::endl; if (HyprlandService::isFloatingRulePresent()) {
} else if (argc == 4 && argv[2] == std::string("-m")) { for (auto& c : HyprlandService::getClientsOnActiveWorkspace()) {
try { HyprlandService::setClientTiled(c);
HyprlandService::moveToWorkspace(std::stoi(argv[3]));
} catch (std::invalid_argument) {
help(argv[0]);
} }
HyprlandService::setFloatingRule(false);
} else { } else {
help(argv[0]); for (auto& c : HyprlandService::getClientsOnActiveWorkspace()) {
HyprlandService::setClientFloating(c);
} }
} else { HyprlandService::setFloatingRule(true);
help(argv[0]);
} }
}
else (help(argv[0]));
exit(0); exit(0);
} }