Skip to content

Commit 144c7b6

Browse files
committed
ipc
1 parent ca8c3e4 commit 144c7b6

12 files changed

Lines changed: 365 additions & 149 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ result
2222
protocols/*.hpp
2323
protocols/*.cpp
2424

25+
hw-protocols/*.hpp
26+
hw-protocols/*.cpp
27+
2528
.cache/
2629

2730
hyprctl/hyprctl

CMakeLists.txt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ execute_process(
4141
OUTPUT_VARIABLE GIT_DIRTY
4242
OUTPUT_STRIP_TRAILING_WHITESPACE)
4343

44-
include_directories(.)
44+
include_directories(. hw-protocols protocols)
4545
set(CMAKE_CXX_STANDARD 23)
4646
add_compile_options(-DWLR_USE_UNSTABLE)
4747
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value
@@ -59,13 +59,16 @@ pkg_check_modules(
5959
hyprutils>=0.2.4
6060
wayland-client
6161
hyprtoolkit>=0.4.0
62+
hyprwire
6263
pixman-1
6364
libdrm)
6465

6566
file(GLOB_RECURSE SRCFILES "src/*.cpp")
6667

6768
add_executable(hyprpaper ${SRCFILES})
6869

70+
# Wayland
71+
6972
pkg_get_variable(WAYLAND_PROTOCOLS_DIR wayland-protocols pkgdatadir)
7073
message(STATUS "Found wayland-protocols at ${WAYLAND_PROTOCOLS_DIR}")
7174
pkg_get_variable(WAYLAND_SCANNER_PKGDATA_DIR wayland-scanner pkgdatadir)
@@ -107,6 +110,25 @@ protocolnew("stable/xdg-shell" "xdg-shell" false)
107110
protocolnew("staging/cursor-shape" "cursor-shape-v1" false)
108111
protocolnew("stable/tablet" "tablet-v2" false)
109112

113+
# Hyprwire
114+
115+
function(hyprprotocolServer protoPath protoName)
116+
set(path ${CMAKE_SOURCE_DIR}/${protoPath})
117+
add_custom_command(
118+
OUTPUT ${CMAKE_SOURCE_DIR}/hw-protocols/${protoName}-server.cpp
119+
${CMAKE_SOURCE_DIR}/hw-protocols/${protoName}-server.hpp
120+
COMMAND hyprwire-scanner ${path}/${protoName}.xml
121+
${CMAKE_SOURCE_DIR}/hw-protocols/
122+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
123+
target_sources(hyprpaper PRIVATE hw-protocols/${protoName}-server.cpp
124+
hw-protocols/${protoName}-server.hpp
125+
)
126+
endfunction()
127+
128+
hyprprotocolServer(hw-protocols hyprpaper_core)
129+
130+
#
131+
110132
string(REPLACE "\"" " " GIT_COMMIT_MESSAGE_ESCAPED "${GIT_COMMIT_MESSAGE}")
111133
target_compile_definitions(hyprpaper
112134
PRIVATE "-DGIT_COMMIT_HASH=\"${GIT_COMMIT_HASH}\"")

hw-protocols/hyprpaper_core.xml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<protocol name="hyprpaper_core" version="1">
3+
<copyright>
4+
BSD 3-Clause License
5+
6+
Copyright (c) 2025, Hypr Development
7+
8+
Redistribution and use in source and binary forms, with or without
9+
modification, are permitted provided that the following conditions are met:
10+
11+
1. Redistributions of source code must retain the above copyright notice, this
12+
list of conditions and the following disclaimer.
13+
14+
2. Redistributions in binary form must reproduce the above copyright notice,
15+
this list of conditions and the following disclaimer in the documentation
16+
and/or other materials provided with the distribution.
17+
18+
3. Neither the name of the copyright holder nor the names of its
19+
contributors may be used to endorse or promote products derived from
20+
this software without specific prior written permission.
21+
22+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32+
</copyright>
33+
34+
<object name="hyprpaper_core_manager" version="1">
35+
<description summary="manager object">
36+
This is the core manager object for hyprpaper operations
37+
</description>
38+
39+
<c2s name="get_wallpaper_object">
40+
<description summary="Get a wallpaper object">
41+
Creates a wallpaper object
42+
</description>
43+
<returns iface="hyprpaper_wallpaper"/>
44+
</c2s>
45+
46+
<s2c name="add_monitor">
47+
<description summary="New monitor added">
48+
Emitted when a new monitor is added.
49+
</description>
50+
<arg name="monitor_name" type="varchar" summary="the monitor's name"/>
51+
</s2c>
52+
53+
<s2c name="remove_monitor">
54+
<description summary="A monitor was removed">
55+
Emitted when a monitor is removed.
56+
</description>
57+
<arg name="monitor_name" type="varchar" summary="the monitor's name"/>
58+
</s2c>
59+
60+
<c2s name="destroy" destructor="true">
61+
<description summary="Destroy this object">
62+
Destroys this object. Children remain alive until destroyed.
63+
</description>
64+
</c2s>
65+
</object>
66+
67+
<enum name="wallpaper_fit_mode">
68+
<value idx="0" name="stretch"/>
69+
<value idx="1" name="cover"/>
70+
<value idx="2" name="contain"/>
71+
<value idx="3" name="tile"/>
72+
</enum>
73+
74+
<enum name="wallpaper_errors">
75+
<value idx="0" name="inert_wallpaper_object" description="attempted to use an inert wallpaper object"/>
76+
</enum>
77+
78+
<enum name="applying_error">
79+
<value idx="0" name="invalid_path" description="path provided was invalid"/>
80+
<value idx="1" name="invalid_monitor" description="monitor provided was invalid"/>
81+
<value idx="2" name="unknown_error" description="unknown error"/>
82+
</enum>
83+
84+
<object name="hyprpaper_wallpaper" version="1">
85+
<description summary="wallpaper object">
86+
This is an object describing a wallpaper
87+
</description>
88+
89+
<c2s name="path">
90+
<description summary="Set a path">
91+
Set a file path for the wallpaper. This has to be an absolute path from the fs root.
92+
This is required.
93+
</description>
94+
<arg name="wallpaper" type="varchar" summary="path"/>
95+
</c2s>
96+
97+
<c2s name="fit_mode">
98+
<description summary="Set a fit mode">
99+
Set a fit mode for the wallpaper. This is set to cover by default.
100+
</description>
101+
<arg name="fit_mode" type="enum" interface="wallpaper_fit_mode" summary="path"/>
102+
</c2s>
103+
104+
<c2s name="monitor_name">
105+
<description summary="Set the monitor name">
106+
Set a monitor for the wallpaper. Setting this to empty (or not setting at all) will
107+
treat this as a wildcard fallback.
108+
109+
See hyprpaper_core_manager.add_monitor and hyprpaper_core_manager.remove_monitor
110+
for tracking monitor names.
111+
</description>
112+
<arg name="monitor_name" type="varchar" summary="monitor name"/>
113+
</c2s>
114+
115+
<c2s name="apply">
116+
<description summary="Apply this wallpaper">
117+
Applies this object's state to the wallpaper state. Will emit .success on success,
118+
and .failed on failure.
119+
120+
This object becomes inert after .succeess or .failed, the only valid operation
121+
is to destroy it afterwards.
122+
</description>
123+
</c2s>
124+
125+
<s2c name="success">
126+
<description summary="Operation succeeded">
127+
Wallpaper was applied successfully.
128+
</description>
129+
</s2c>
130+
131+
<s2c name="failed">
132+
<description summary="Operation failed">
133+
Wallpaper was not applied. See the error field for more information.
134+
</description>
135+
<arg name="error" type="enum" interface="hyprpaper_wallpaper_application_error" summary="path"/>
136+
</s2c>
137+
138+
<c2s name="destroy" destructor="true">
139+
<description summary="Destroy this object">
140+
Destroys this object.
141+
</description>
142+
</c2s>
143+
</object>
144+
</protocol>

src/config/ConfigManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ std::vector<CConfigManager::SSetting> CConfigManager::getSettings() {
9494
continue;
9595
}
9696

97-
result.emplace_back(SSetting{.monitor = std::move(monitor), .fitMode = std::move(fitMode), .path = RESOLVE_PATH.value(), .id = ++m_maxId});
97+
result.emplace_back(SSetting{.monitor = std::move(monitor), .fitMode = std::move(fitMode), .path = RESOLVE_PATH.value()});
9898
}
9999

100100
return result;

src/config/ConfigManager.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class CConfigManager {
2929
Hyprlang::CConfig m_config;
3030

3131
std::string m_currentConfigPath;
32-
uint32_t m_maxId = 0;
3332
};
3433

3534
inline UP<CConfigManager> g_config;

src/config/WallpaperMatcher.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
#include <algorithm>
44

55
void CWallpaperMatcher::addState(CConfigManager::SSetting&& s) {
6+
s.id = ++m_maxId;
7+
68
std::erase_if(m_settings, [&s](const auto& e) { return e.monitor == s.monitor; });
79
m_settings.emplace_back(std::move(s));
810
recalcStates();
911
}
1012

1113
void CWallpaperMatcher::addStates(std::vector<CConfigManager::SSetting>&& s) {
14+
for (auto& ss : s) {
15+
ss.id = ++m_maxId;
16+
}
17+
1218
std::erase_if(m_settings, [&s](const auto& e) { return std::ranges::any_of(s, [&e](const auto& el) { return el.monitor == e.monitor; }); });
1319
m_settings.append_range(std::move(s));
1420
recalcStates();
@@ -25,6 +31,10 @@ void CWallpaperMatcher::unregisterOutput(const std::string_view& s) {
2531
recalcStates();
2632
}
2733

34+
bool CWallpaperMatcher::outputExists(const std::string_view& s) {
35+
return std::ranges::contains(m_monitorNames, s);
36+
}
37+
2838
std::optional<CWallpaperMatcher::rw<const CConfigManager::SSetting>> CWallpaperMatcher::getSetting(const std::string_view& monName) {
2939
for (const auto& m : m_monitorStates) {
3040
if (m.name != monName)

src/config/WallpaperMatcher.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class CWallpaperMatcher {
2323

2424
void registerOutput(const std::string_view&);
2525
void unregisterOutput(const std::string_view&);
26+
bool outputExists(const std::string_view&);
2627

2728
std::optional<rw<const CConfigManager::SSetting>> getSetting(const std::string_view& monName);
2829

@@ -44,6 +45,8 @@ class CWallpaperMatcher {
4445
std::vector<std::string> m_monitorNames;
4546
std::vector<SMonitorState> m_monitorStates;
4647

48+
uint32_t m_maxId = 0;
49+
4750
SMonitorState& getState(const std::string_view& monName);
4851
};
4952

0 commit comments

Comments
 (0)