mirror of
https://github.com/hyprwm/hyprlock.git
synced 2025-05-12 21:30:37 +01:00
implement mpvpaper
This commit is contained in:
parent
eb28b37e14
commit
4d8bf760b3
17 changed files with 2061 additions and 1217 deletions
|
@ -28,9 +28,6 @@ set(CMAKE_CXX_STANDARD 23)
|
|||
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-value
|
||||
-Wno-missing-field-initializers -Wno-narrowing)
|
||||
|
||||
|
||||
|
||||
|
||||
add_compile_definitions(HYPRLOCK_VERSION="${VERSION}")
|
||||
|
||||
if (DEFINED HYPRLOCK_COMMIT)
|
||||
|
@ -135,6 +132,7 @@ make_directory(${CMAKE_SOURCE_DIR}/protocols) # we don't ship any custom ones so
|
|||
|
||||
protocolwayland()
|
||||
|
||||
protocolnew("stable/xdg-shell" "xdg-shell" false) # Added for xdg-shell
|
||||
protocolnew("protocols" "wlr-screencopy-unstable-v1" true)
|
||||
protocolnew("staging/ext-session-lock" "ext-session-lock-v1" false)
|
||||
protocolnew("stable/linux-dmabuf" "linux-dmabuf-v1" false)
|
||||
|
@ -142,6 +140,7 @@ protocolnew("staging/fractional-scale" "fractional-scale-v1" false)
|
|||
protocolnew("stable/viewporter" "viewporter" false)
|
||||
protocolnew("staging/cursor-shape" "cursor-shape-v1" false)
|
||||
protocolnew("stable/tablet" "tablet-v2" false)
|
||||
protocolnew("protocols" "wlr-layer-shell-unstable-v1" true)
|
||||
|
||||
# Installation
|
||||
install(TARGETS hyprlock)
|
||||
|
@ -152,4 +151,4 @@ install(FILES ${CMAKE_SOURCE_DIR}/pam/hyprlock
|
|||
install(
|
||||
FILES ${CMAKE_SOURCE_DIR}/assets/example.conf
|
||||
DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/hypr
|
||||
RENAME hyprlock.conf)
|
||||
RENAME hyprlock.conf)
|
407
protocols/wlr-layer-shell-unstable-v1.xml
Normal file
407
protocols/wlr-layer-shell-unstable-v1.xml
Normal file
|
@ -0,0 +1,407 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<protocol name="wlr_layer_shell_unstable_v1">
|
||||
<copyright>
|
||||
Copyright © 2017 Drew DeVault
|
||||
|
||||
Permission to use, copy, modify, distribute, and sell this
|
||||
software and its documentation for any purpose is hereby granted
|
||||
without fee, provided that the above copyright notice appear in
|
||||
all copies and that both that copyright notice and this permission
|
||||
notice appear in supporting documentation, and that the name of
|
||||
the copyright holders not be used in advertising or publicity
|
||||
pertaining to distribution of the software without specific,
|
||||
written prior permission. The copyright holders make no
|
||||
representations about the suitability of this software for any
|
||||
purpose. It is provided "as is" without express or implied
|
||||
warranty.
|
||||
|
||||
THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
||||
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
|
||||
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
||||
THIS SOFTWARE.
|
||||
</copyright>
|
||||
|
||||
<interface name="zwlr_layer_shell_v1" version="5">
|
||||
<description summary="create surfaces that are layers of the desktop">
|
||||
Clients can use this interface to assign the surface_layer role to
|
||||
wl_surfaces. Such surfaces are assigned to a "layer" of the output and
|
||||
rendered with a defined z-depth respective to each other. They may also be
|
||||
anchored to the edges and corners of a screen and specify input handling
|
||||
semantics. This interface should be suitable for the implementation of
|
||||
many desktop shell components, and a broad number of other applications
|
||||
that interact with the desktop.
|
||||
</description>
|
||||
|
||||
<request name="get_layer_surface">
|
||||
<description summary="create a layer_surface from a surface">
|
||||
Create a layer surface for an existing surface. This assigns the role of
|
||||
layer_surface, or raises a protocol error if another role is already
|
||||
assigned.
|
||||
|
||||
Creating a layer surface from a wl_surface which has a buffer attached
|
||||
or committed is a client error, and any attempts by a client to attach
|
||||
or manipulate a buffer prior to the first layer_surface.configure call
|
||||
must also be treated as errors.
|
||||
|
||||
After creating a layer_surface object and setting it up, the client
|
||||
must perform an initial commit without any buffer attached.
|
||||
The compositor will reply with a layer_surface.configure event.
|
||||
The client must acknowledge it and is then allowed to attach a buffer
|
||||
to map the surface.
|
||||
|
||||
You may pass NULL for output to allow the compositor to decide which
|
||||
output to use. Generally this will be the one that the user most
|
||||
recently interacted with.
|
||||
|
||||
Clients can specify a namespace that defines the purpose of the layer
|
||||
surface.
|
||||
</description>
|
||||
<arg name="id" type="new_id" interface="zwlr_layer_surface_v1"/>
|
||||
<arg name="surface" type="object" interface="wl_surface"/>
|
||||
<arg name="output" type="object" interface="wl_output" allow-null="true"/>
|
||||
<arg name="layer" type="uint" enum="layer" summary="layer to add this surface to"/>
|
||||
<arg name="namespace" type="string" summary="namespace for the layer surface"/>
|
||||
</request>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="role" value="0" summary="wl_surface has another role"/>
|
||||
<entry name="invalid_layer" value="1" summary="layer value is invalid"/>
|
||||
<entry name="already_constructed" value="2" summary="wl_surface has a buffer attached or committed"/>
|
||||
</enum>
|
||||
|
||||
<enum name="layer">
|
||||
<description summary="available layers for surfaces">
|
||||
These values indicate which layers a surface can be rendered in. They
|
||||
are ordered by z depth, bottom-most first. Traditional shell surfaces
|
||||
will typically be rendered between the bottom and top layers.
|
||||
Fullscreen shell surfaces are typically rendered at the top layer.
|
||||
Multiple surfaces can share a single layer, and ordering within a
|
||||
single layer is undefined.
|
||||
</description>
|
||||
|
||||
<entry name="background" value="0"/>
|
||||
<entry name="bottom" value="1"/>
|
||||
<entry name="top" value="2"/>
|
||||
<entry name="overlay" value="3"/>
|
||||
</enum>
|
||||
|
||||
<!-- Version 3 additions -->
|
||||
|
||||
<request name="destroy" type="destructor" since="3">
|
||||
<description summary="destroy the layer_shell object">
|
||||
This request indicates that the client will not use the layer_shell
|
||||
object any more. Objects that have been created through this instance
|
||||
are not affected.
|
||||
</description>
|
||||
</request>
|
||||
</interface>
|
||||
|
||||
<interface name="zwlr_layer_surface_v1" version="5">
|
||||
<description summary="layer metadata interface">
|
||||
An interface that may be implemented by a wl_surface, for surfaces that
|
||||
are designed to be rendered as a layer of a stacked desktop-like
|
||||
environment.
|
||||
|
||||
Layer surface state (layer, size, anchor, exclusive zone,
|
||||
margin, interactivity) is double-buffered, and will be applied at the
|
||||
time wl_surface.commit of the corresponding wl_surface is called.
|
||||
|
||||
Attaching a null buffer to a layer surface unmaps it.
|
||||
|
||||
Unmapping a layer_surface means that the surface cannot be shown by the
|
||||
compositor until it is explicitly mapped again. The layer_surface
|
||||
returns to the state it had right after layer_shell.get_layer_surface.
|
||||
The client can re-map the surface by performing a commit without any
|
||||
buffer attached, waiting for a configure event and handling it as usual.
|
||||
</description>
|
||||
|
||||
<request name="set_size">
|
||||
<description summary="sets the size of the surface">
|
||||
Sets the size of the surface in surface-local coordinates. The
|
||||
compositor will display the surface centered with respect to its
|
||||
anchors.
|
||||
|
||||
If you pass 0 for either value, the compositor will assign it and
|
||||
inform you of the assignment in the configure event. You must set your
|
||||
anchor to opposite edges in the dimensions you omit; not doing so is a
|
||||
protocol error. Both values are 0 by default.
|
||||
|
||||
Size is double-buffered, see wl_surface.commit.
|
||||
</description>
|
||||
<arg name="width" type="uint"/>
|
||||
<arg name="height" type="uint"/>
|
||||
</request>
|
||||
|
||||
<request name="set_anchor">
|
||||
<description summary="configures the anchor point of the surface">
|
||||
Requests that the compositor anchor the surface to the specified edges
|
||||
and corners. If two orthogonal edges are specified (e.g. 'top' and
|
||||
'left'), then the anchor point will be the intersection of the edges
|
||||
(e.g. the top left corner of the output); otherwise the anchor point
|
||||
will be centered on that edge, or in the center if none is specified.
|
||||
|
||||
Anchor is double-buffered, see wl_surface.commit.
|
||||
</description>
|
||||
<arg name="anchor" type="uint" enum="anchor"/>
|
||||
</request>
|
||||
|
||||
<request name="set_exclusive_zone">
|
||||
<description summary="configures the exclusive geometry of this surface">
|
||||
Requests that the compositor avoids occluding an area with other
|
||||
surfaces. The compositor's use of this information is
|
||||
implementation-dependent - do not assume that this region will not
|
||||
actually be occluded.
|
||||
|
||||
A positive value is only meaningful if the surface is anchored to one
|
||||
edge or an edge and both perpendicular edges. If the surface is not
|
||||
anchored, anchored to only two perpendicular edges (a corner), anchored
|
||||
to only two parallel edges or anchored to all edges, a positive value
|
||||
will be treated the same as zero.
|
||||
|
||||
A positive zone is the distance from the edge in surface-local
|
||||
coordinates to consider exclusive.
|
||||
|
||||
Surfaces that do not wish to have an exclusive zone may instead specify
|
||||
how they should interact with surfaces that do. If set to zero, the
|
||||
surface indicates that it would like to be moved to avoid occluding
|
||||
surfaces with a positive exclusive zone. If set to -1, the surface
|
||||
indicates that it would not like to be moved to accommodate for other
|
||||
surfaces, and the compositor should extend it all the way to the edges
|
||||
it is anchored to.
|
||||
|
||||
For example, a panel might set its exclusive zone to 10, so that
|
||||
maximized shell surfaces are not shown on top of it. A notification
|
||||
might set its exclusive zone to 0, so that it is moved to avoid
|
||||
occluding the panel, but shell surfaces are shown underneath it. A
|
||||
wallpaper or lock screen might set their exclusive zone to -1, so that
|
||||
they stretch below or over the panel.
|
||||
|
||||
The default value is 0.
|
||||
|
||||
Exclusive zone is double-buffered, see wl_surface.commit.
|
||||
</description>
|
||||
<arg name="zone" type="int"/>
|
||||
</request>
|
||||
|
||||
<request name="set_margin">
|
||||
<description summary="sets a margin from the anchor point">
|
||||
Requests that the surface be placed some distance away from the anchor
|
||||
point on the output, in surface-local coordinates. Setting this value
|
||||
for edges you are not anchored to has no effect.
|
||||
|
||||
The exclusive zone includes the margin.
|
||||
|
||||
Margin is double-buffered, see wl_surface.commit.
|
||||
</description>
|
||||
<arg name="top" type="int"/>
|
||||
<arg name="right" type="int"/>
|
||||
<arg name="bottom" type="int"/>
|
||||
<arg name="left" type="int"/>
|
||||
</request>
|
||||
|
||||
<enum name="keyboard_interactivity">
|
||||
<description summary="types of keyboard interaction possible for a layer shell surface">
|
||||
Types of keyboard interaction possible for layer shell surfaces. The
|
||||
rationale for this is twofold: (1) some applications are not interested
|
||||
in keyboard events and not allowing them to be focused can improve the
|
||||
desktop experience; (2) some applications will want to take exclusive
|
||||
keyboard focus.
|
||||
</description>
|
||||
|
||||
<entry name="none" value="0">
|
||||
<description summary="no keyboard focus is possible">
|
||||
This value indicates that this surface is not interested in keyboard
|
||||
events and the compositor should never assign it the keyboard focus.
|
||||
|
||||
This is the default value, set for newly created layer shell surfaces.
|
||||
|
||||
This is useful for e.g. desktop widgets that display information or
|
||||
only have interaction with non-keyboard input devices.
|
||||
</description>
|
||||
</entry>
|
||||
<entry name="exclusive" value="1">
|
||||
<description summary="request exclusive keyboard focus">
|
||||
Request exclusive keyboard focus if this surface is above the shell surface layer.
|
||||
|
||||
For the top and overlay layers, the seat will always give
|
||||
exclusive keyboard focus to the top-most layer which has keyboard
|
||||
interactivity set to exclusive. If this layer contains multiple
|
||||
surfaces with keyboard interactivity set to exclusive, the compositor
|
||||
determines the one receiving keyboard events in an implementation-
|
||||
defined manner. In this case, no guarantee is made when this surface
|
||||
will receive keyboard focus (if ever).
|
||||
|
||||
For the bottom and background layers, the compositor is allowed to use
|
||||
normal focus semantics.
|
||||
|
||||
This setting is mainly intended for applications that need to ensure
|
||||
they receive all keyboard events, such as a lock screen or a password
|
||||
prompt.
|
||||
</description>
|
||||
</entry>
|
||||
<entry name="on_demand" value="2" since="4">
|
||||
<description summary="request regular keyboard focus semantics">
|
||||
This requests the compositor to allow this surface to be focused and
|
||||
unfocused by the user in an implementation-defined manner. The user
|
||||
should be able to unfocus this surface even regardless of the layer
|
||||
it is on.
|
||||
|
||||
Typically, the compositor will want to use its normal mechanism to
|
||||
manage keyboard focus between layer shell surfaces with this setting
|
||||
and regular toplevels on the desktop layer (e.g. click to focus).
|
||||
Nevertheless, it is possible for a compositor to require a special
|
||||
interaction to focus or unfocus layer shell surfaces (e.g. requiring
|
||||
a click even if focus follows the mouse normally, or providing a
|
||||
keybinding to switch focus between layers).
|
||||
|
||||
This setting is mainly intended for desktop shell components (e.g.
|
||||
panels) that allow keyboard interaction. Using this option can allow
|
||||
implementing a desktop shell that can be fully usable without the
|
||||
mouse.
|
||||
</description>
|
||||
</entry>
|
||||
</enum>
|
||||
|
||||
<request name="set_keyboard_interactivity">
|
||||
<description summary="requests keyboard events">
|
||||
Set how keyboard events are delivered to this surface. By default,
|
||||
layer shell surfaces do not receive keyboard events; this request can
|
||||
be used to change this.
|
||||
|
||||
This setting is inherited by child surfaces set by the get_popup
|
||||
request.
|
||||
|
||||
Layer surfaces receive pointer, touch, and tablet events normally. If
|
||||
you do not want to receive them, set the input region on your surface
|
||||
to an empty region.
|
||||
|
||||
Keyboard interactivity is double-buffered, see wl_surface.commit.
|
||||
</description>
|
||||
<arg name="keyboard_interactivity" type="uint" enum="keyboard_interactivity"/>
|
||||
</request>
|
||||
|
||||
<request name="get_popup">
|
||||
<description summary="assign this layer_surface as an xdg_popup parent">
|
||||
This assigns an xdg_popup's parent to this layer_surface. This popup
|
||||
should have been created via xdg_surface::get_popup with the parent set
|
||||
to NULL, and this request must be invoked before committing the popup's
|
||||
initial state.
|
||||
|
||||
See the documentation of xdg_popup for more details about what an
|
||||
xdg_popup is and how it is used.
|
||||
</description>
|
||||
<arg name="popup" type="object" interface="xdg_popup"/>
|
||||
</request>
|
||||
|
||||
<request name="ack_configure">
|
||||
<description summary="ack a configure event">
|
||||
When a configure event is received, if a client commits the
|
||||
surface in response to the configure event, then the client
|
||||
must make an ack_configure request sometime before the commit
|
||||
request, passing along the serial of the configure event.
|
||||
|
||||
If the client receives multiple configure events before it
|
||||
can respond to one, it only has to ack the last configure event.
|
||||
|
||||
A client is not required to commit immediately after sending
|
||||
an ack_configure request - it may even ack_configure several times
|
||||
before its next surface commit.
|
||||
|
||||
A client may send multiple ack_configure requests before committing, but
|
||||
only the last request sent before a commit indicates which configure
|
||||
event the client really is responding to.
|
||||
</description>
|
||||
<arg name="serial" type="uint" summary="the serial from the configure event"/>
|
||||
</request>
|
||||
|
||||
<request name="destroy" type="destructor">
|
||||
<description summary="destroy the layer_surface">
|
||||
This request destroys the layer surface.
|
||||
</description>
|
||||
</request>
|
||||
|
||||
<event name="configure">
|
||||
<description summary="suggest a surface change">
|
||||
The configure event asks the client to resize its surface.
|
||||
|
||||
Clients should arrange their surface for the new states, and then send
|
||||
an ack_configure request with the serial sent in this configure event at
|
||||
some point before committing the new surface.
|
||||
|
||||
The client is free to dismiss all but the last configure event it
|
||||
received.
|
||||
|
||||
The width and height arguments specify the size of the window in
|
||||
surface-local coordinates.
|
||||
|
||||
The size is a hint, in the sense that the client is free to ignore it if
|
||||
it doesn't resize, pick a smaller size (to satisfy aspect ratio or
|
||||
resize in steps of NxM pixels). If the client picks a smaller size and
|
||||
is anchored to two opposite anchors (e.g. 'top' and 'bottom'), the
|
||||
surface will be centered on this axis.
|
||||
|
||||
If the width or height arguments are zero, it means the client should
|
||||
decide its own window dimension.
|
||||
</description>
|
||||
<arg name="serial" type="uint"/>
|
||||
<arg name="width" type="uint"/>
|
||||
<arg name="height" type="uint"/>
|
||||
</event>
|
||||
|
||||
<event name="closed">
|
||||
<description summary="surface should be closed">
|
||||
The closed event is sent by the compositor when the surface will no
|
||||
longer be shown. The output may have been destroyed or the user may
|
||||
have asked for it to be removed. Further changes to the surface will be
|
||||
ignored. The client should destroy the resource after receiving this
|
||||
event, and create a new surface if they so choose.
|
||||
</description>
|
||||
</event>
|
||||
|
||||
<enum name="error">
|
||||
<entry name="invalid_surface_state" value="0" summary="provided surface state is invalid"/>
|
||||
<entry name="invalid_size" value="1" summary="size is invalid"/>
|
||||
<entry name="invalid_anchor" value="2" summary="anchor bitfield is invalid"/>
|
||||
<entry name="invalid_keyboard_interactivity" value="3" summary="keyboard interactivity is invalid"/>
|
||||
<entry name="invalid_exclusive_edge" value="4" summary="exclusive edge is invalid given the surface anchors"/>
|
||||
</enum>
|
||||
|
||||
<enum name="anchor" bitfield="true">
|
||||
<entry name="top" value="1" summary="the top edge of the anchor rectangle"/>
|
||||
<entry name="bottom" value="2" summary="the bottom edge of the anchor rectangle"/>
|
||||
<entry name="left" value="4" summary="the left edge of the anchor rectangle"/>
|
||||
<entry name="right" value="8" summary="the right edge of the anchor rectangle"/>
|
||||
</enum>
|
||||
|
||||
<!-- Version 2 additions -->
|
||||
|
||||
<request name="set_layer" since="2">
|
||||
<description summary="change the layer of the surface">
|
||||
Change the layer that the surface is rendered on.
|
||||
|
||||
Layer is double-buffered, see wl_surface.commit.
|
||||
</description>
|
||||
<arg name="layer" type="uint" enum="zwlr_layer_shell_v1.layer" summary="layer to move this surface to"/>
|
||||
</request>
|
||||
|
||||
<!-- Version 5 additions -->
|
||||
|
||||
<request name="set_exclusive_edge" since="5">
|
||||
<description summary="set the edge the exclusive zone will be applied to">
|
||||
Requests an edge for the exclusive zone to apply. The exclusive
|
||||
edge will be automatically deduced from anchor points when possible,
|
||||
but when the surface is anchored to a corner, it will be necessary
|
||||
to set it explicitly to disambiguate, as it is not possible to deduce
|
||||
which one of the two corner edges should be used.
|
||||
|
||||
The edge must be one the surface is anchored to, otherwise the
|
||||
invalid_exclusive_edge protocol error will be raised.
|
||||
</description>
|
||||
<arg name="edge" type="uint" enum="anchor"/>
|
||||
</request>
|
||||
</interface>
|
||||
</protocol>
|
|
@ -202,7 +202,6 @@ inline static constexpr auto LAYOUTCONFIG = [](const char* default_value) -> Hyp
|
|||
return Hyprlang::CUSTOMTYPE{&configHandleLayoutOption, configHandleLayoutOptionDestroy, default_value};
|
||||
};
|
||||
void CConfigManager::init() {
|
||||
|
||||
#define SHADOWABLE(name) \
|
||||
m_config.addSpecialConfigValue(name, "shadow_size", Hyprlang::INT{3}); \
|
||||
m_config.addSpecialConfigValue(name, "shadow_passes", Hyprlang::INT{0}); \
|
||||
|
@ -242,6 +241,7 @@ void CConfigManager::init() {
|
|||
m_config.addSpecialConfigValue("background", "reload_time", Hyprlang::INT{-1});
|
||||
m_config.addSpecialConfigValue("background", "reload_cmd", Hyprlang::STRING{""});
|
||||
m_config.addSpecialConfigValue("background", "crossfade_time", Hyprlang::FLOAT{-1.0});
|
||||
m_config.addSpecialConfigValue("background", "fallback_path", Hyprlang::STRING{""});
|
||||
|
||||
m_config.addSpecialCategory("shape", Hyprlang::SSpecialCategoryOptions{.key = nullptr, .anonymousKeyBased = true});
|
||||
m_config.addSpecialConfigValue("shape", "monitor", Hyprlang::STRING{""});
|
||||
|
@ -356,281 +356,283 @@ void CConfigManager::init() {
|
|||
Debug::log(ERR, "Config has errors:\n{}\nProceeding ignoring faulty entries", result.getError());
|
||||
|
||||
#undef SHADOWABLE
|
||||
}
|
||||
std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
||||
std::vector<CConfigManager::SWidgetConfig> result;
|
||||
|
||||
}
|
||||
|
||||
std::vector<CConfigManager::SWidgetConfig> CConfigManager::getWidgetConfigs() {
|
||||
std::vector<CConfigManager::SWidgetConfig> result;
|
||||
|
||||
#define SHADOWABLE(name) \
|
||||
{"shadow_size", m_config.getSpecialConfigValue(name, "shadow_size", k.c_str())}, {"shadow_passes", m_config.getSpecialConfigValue(name, "shadow_passes", k.c_str())}, \
|
||||
{"shadow_color", m_config.getSpecialConfigValue(name, "shadow_color", k.c_str())}, { \
|
||||
"shadow_boost", m_config.getSpecialConfigValue(name, "shadow_boost", k.c_str()) \
|
||||
}
|
||||
|
||||
//
|
||||
auto keys = m_config.listKeysForSpecialCategory("background");
|
||||
result.reserve(keys.size());
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "background",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("background", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"type", m_config.getSpecialConfigValue("background", "type", k.c_str())}, // New type field
|
||||
{"path", m_config.getSpecialConfigValue("background", "path", k.c_str())},
|
||||
{"color", m_config.getSpecialConfigValue("background", "color", k.c_str())},
|
||||
{"blur_size", m_config.getSpecialConfigValue("background", "blur_size", k.c_str())},
|
||||
{"blur_passes", m_config.getSpecialConfigValue("background", "blur_passes", k.c_str())},
|
||||
{"noise", m_config.getSpecialConfigValue("background", "noise", k.c_str())},
|
||||
{"contrast", m_config.getSpecialConfigValue("background", "contrast", k.c_str())},
|
||||
{"vibrancy", m_config.getSpecialConfigValue("background", "vibrancy", k.c_str())},
|
||||
{"brightness", m_config.getSpecialConfigValue("background", "brightness", k.c_str())},
|
||||
{"vibrancy_darkness", m_config.getSpecialConfigValue("background", "vibrancy_darkness", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("background", "zindex", k.c_str())},
|
||||
{"reload_time", m_config.getSpecialConfigValue("background", "reload_time", k.c_str())},
|
||||
{"reload_cmd", m_config.getSpecialConfigValue("background", "reload_cmd", k.c_str())},
|
||||
{"crossfade_time", m_config.getSpecialConfigValue("background", "crossfade_time", k.c_str())},
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
//
|
||||
keys = m_config.listKeysForSpecialCategory("shape");
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "shape",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("shape", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"size", m_config.getSpecialConfigValue("shape", "size", k.c_str())},
|
||||
{"rounding", m_config.getSpecialConfigValue("shape", "rounding", k.c_str())},
|
||||
{"border_size", m_config.getSpecialConfigValue("shape", "border_size", k.c_str())},
|
||||
{"border_color", m_config.getSpecialConfigValue("shape", "border_color", k.c_str())},
|
||||
{"color", m_config.getSpecialConfigValue("shape", "color", k.c_str())},
|
||||
{"position", m_config.getSpecialConfigValue("shape", "position", k.c_str())},
|
||||
{"halign", m_config.getSpecialConfigValue("shape", "halign", k.c_str())},
|
||||
{"valign", m_config.getSpecialConfigValue("shape", "valign", k.c_str())},
|
||||
{"rotate", m_config.getSpecialConfigValue("shape", "rotate", k.c_str())},
|
||||
{"xray", m_config.getSpecialConfigValue("shape", "xray", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("shape", "zindex", k.c_str())},
|
||||
SHADOWABLE("shape"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
//
|
||||
keys = m_config.listKeysForSpecialCategory("image");
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "image",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("image", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"path", m_config.getSpecialConfigValue("image", "path", k.c_str())},
|
||||
{"size", m_config.getSpecialConfigValue("image", "size", k.c_str())},
|
||||
{"rounding", m_config.getSpecialConfigValue("image", "rounding", k.c_str())},
|
||||
{"border_size", m_config.getSpecialConfigValue("image", "border_size", k.c_str())},
|
||||
{"border_color", m_config.getSpecialConfigValue("image", "border_color", k.c_str())},
|
||||
{"position", m_config.getSpecialConfigValue("image", "position", k.c_str())},
|
||||
{"halign", m_config.getSpecialConfigValue("image", "halign", k.c_str())},
|
||||
{"valign", m_config.getSpecialConfigValue("image", "valign", k.c_str())},
|
||||
{"rotate", m_config.getSpecialConfigValue("image", "rotate", k.c_str())},
|
||||
{"reload_time", m_config.getSpecialConfigValue("image", "reload_time", k.c_str())},
|
||||
{"reload_cmd", m_config.getSpecialConfigValue("image", "reload_cmd", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("image", "zindex", k.c_str())},
|
||||
SHADOWABLE("image"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
keys = m_config.listKeysForSpecialCategory("input-field");
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "input-field",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("input-field", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"size", m_config.getSpecialConfigValue("input-field", "size", k.c_str())},
|
||||
{"inner_color", m_config.getSpecialConfigValue("input-field", "inner_color", k.c_str())},
|
||||
{"outer_color", m_config.getSpecialConfigValue("input-field", "outer_color", k.c_str())},
|
||||
{"outline_thickness", m_config.getSpecialConfigValue("input-field", "outline_thickness", k.c_str())},
|
||||
{"dots_size", m_config.getSpecialConfigValue("input-field", "dots_size", k.c_str())},
|
||||
{"dots_spacing", m_config.getSpecialConfigValue("input-field", "dots_spacing", k.c_str())},
|
||||
{"dots_center", m_config.getSpecialConfigValue("input-field", "dots_center", k.c_str())},
|
||||
{"dots_rounding", m_config.getSpecialConfigValue("input-field", "dots_rounding", k.c_str())},
|
||||
{"dots_text_format", m_config.getSpecialConfigValue("input-field", "dots_text_format", k.c_str())},
|
||||
{"fade_on_empty", m_config.getSpecialConfigValue("input-field", "fade_on_empty", k.c_str())},
|
||||
{"fade_timeout", m_config.getSpecialConfigValue("input-field", "fade_timeout", k.c_str())},
|
||||
{"font_color", m_config.getSpecialConfigValue("input-field", "font_color", k.c_str())},
|
||||
{"font_family", m_config.getSpecialConfigValue("input-field", "font_family", k.c_str())},
|
||||
{"halign", m_config.getSpecialConfigValue("input-field", "halign", k.c_str())},
|
||||
{"valign", m_config.getSpecialConfigValue("input-field", "valign", k.c_str())},
|
||||
{"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())},
|
||||
{"placeholder_text", m_config.getSpecialConfigValue("input-field", "placeholder_text", k.c_str())},
|
||||
{"hide_input", m_config.getSpecialConfigValue("input-field", "hide_input", k.c_str())},
|
||||
{"hide_input_base_color", m_config.getSpecialConfigValue("input-field", "hide_input_base_color", k.c_str())},
|
||||
{"rounding", m_config.getSpecialConfigValue("input-field", "rounding", k.c_str())},
|
||||
{"check_color", m_config.getSpecialConfigValue("input-field", "check_color", k.c_str())},
|
||||
{"fail_color", m_config.getSpecialConfigValue("input-field", "fail_color", k.c_str())},
|
||||
{"fail_text", m_config.getSpecialConfigValue("input-field", "fail_text", k.c_str())},
|
||||
{"capslock_color", m_config.getSpecialConfigValue("input-field", "capslock_color", k.c_str())},
|
||||
{"numlock_color", m_config.getSpecialConfigValue("input-field", "numlock_color", k.c_str())},
|
||||
{"bothlock_color", m_config.getSpecialConfigValue("input-field", "bothlock_color", k.c_str())},
|
||||
{"invert_numlock", m_config.getSpecialConfigValue("input-field", "invert_numlock", k.c_str())},
|
||||
{"swap_font_color", m_config.getSpecialConfigValue("input-field", "swap_font_color", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("input-field", "zindex", k.c_str())},
|
||||
SHADOWABLE("input-field"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
keys = m_config.listKeysForSpecialCategory("label");
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "label",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("label", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"position", m_config.getSpecialConfigValue("label", "position", k.c_str())},
|
||||
{"color", m_config.getSpecialConfigValue("label", "color", k.c_str())},
|
||||
{"font_size", m_config.getSpecialConfigValue("label", "font_size", k.c_str())},
|
||||
{"font_family", m_config.getSpecialConfigValue("label", "font_family", k.c_str())},
|
||||
{"text", m_config.getSpecialConfigValue("label", "text", k.c_str())},
|
||||
{"halign", m_config.getSpecialConfigValue("label", "halign", k.c_str())},
|
||||
{"valign", m_config.getSpecialConfigValue("label", "valign", k.c_str())},
|
||||
{"rotate", m_config.getSpecialConfigValue("label", "rotate", k.c_str())},
|
||||
{"text_align", m_config.getSpecialConfigValue("label", "text_align", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("label", "zindex", k.c_str())},
|
||||
SHADOWABLE("label"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
//
|
||||
auto keys = m_config.listKeysForSpecialCategory("background");
|
||||
result.reserve(keys.size());
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "background",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("background", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"type", m_config.getSpecialConfigValue("background", "type", k.c_str())},
|
||||
{"path", m_config.getSpecialConfigValue("background", "path", k.c_str())},
|
||||
{"color", m_config.getSpecialConfigValue("background", "color", k.c_str())},
|
||||
{"blur_size", m_config.getSpecialConfigValue("background", "blur_size", k.c_str())},
|
||||
{"blur_passes", m_config.getSpecialConfigValue("background", "blur_passes", k.c_str())},
|
||||
{"noise", m_config.getSpecialConfigValue("background", "noise", k.c_str())},
|
||||
{"contrast", m_config.getSpecialConfigValue("background", "contrast", k.c_str())},
|
||||
{"vibrancy", m_config.getSpecialConfigValue("background", "vibrancy", k.c_str())},
|
||||
{"brightness", m_config.getSpecialConfigValue("background", "brightness", k.c_str())},
|
||||
{"vibrancy_darkness", m_config.getSpecialConfigValue("background", "vibrancy_darkness", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("background", "zindex", k.c_str())},
|
||||
{"reload_time", m_config.getSpecialConfigValue("background", "reload_time", k.c_str())},
|
||||
{"reload_cmd", m_config.getSpecialConfigValue("background", "reload_cmd", k.c_str())},
|
||||
{"crossfade_time", m_config.getSpecialConfigValue("background", "crossfade_time", k.c_str())},
|
||||
{"fallback_path", m_config.getSpecialConfigValue("background", "fallback_path", k.c_str())},
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
std::optional<std::string> CConfigManager::handleSource(const std::string& command, const std::string& rawpath) {
|
||||
if (rawpath.length() < 2) {
|
||||
Debug::log(ERR, "source= path garbage");
|
||||
return "source path " + rawpath + " bogus!";
|
||||
|
||||
//
|
||||
keys = m_config.listKeysForSpecialCategory("shape");
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "shape",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("shape", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"size", m_config.getSpecialConfigValue("shape", "size", k.c_str())},
|
||||
{"rounding", m_config.getSpecialConfigValue("shape", "rounding", k.c_str())},
|
||||
{"border_size", m_config.getSpecialConfigValue("shape", "border_size", k.c_str())},
|
||||
{"border_color", m_config.getSpecialConfigValue("shape", "border_color", k.c_str())},
|
||||
{"color", m_config.getSpecialConfigValue("shape", "color", k.c_str())},
|
||||
{"position", m_config.getSpecialConfigValue("shape", "position", k.c_str())},
|
||||
{"halign", m_config.getSpecialConfigValue("shape", "halign", k.c_str())},
|
||||
{"valign", m_config.getSpecialConfigValue("shape", "valign", k.c_str())},
|
||||
{"rotate", m_config.getSpecialConfigValue("shape", "rotate", k.c_str())},
|
||||
{"xray", m_config.getSpecialConfigValue("shape", "xray", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("shape", "zindex", k.c_str())},
|
||||
SHADOWABLE("shape"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
//
|
||||
keys = m_config.listKeysForSpecialCategory("image");
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "image",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("image", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"path", m_config.getSpecialConfigValue("image", "path", k.c_str())},
|
||||
{"size", m_config.getSpecialConfigValue("image", "size", k.c_str())},
|
||||
{"rounding", m_config.getSpecialConfigValue("image", "rounding", k.c_str())},
|
||||
{"border_size", m_config.getSpecialConfigValue("image", "border_size", k.c_str())},
|
||||
{"border_color", m_config.getSpecialConfigValue("image", "border_color", k.c_str())},
|
||||
{"position", m_config.getSpecialConfigValue("image", "position", k.c_str())},
|
||||
{"halign", m_config.getSpecialConfigValue("image", "halign", k.c_str())},
|
||||
{"valign", m_config.getSpecialConfigValue("image", "valign", k.c_str())},
|
||||
{"rotate", m_config.getSpecialConfigValue("image", "rotate", k.c_str())},
|
||||
{"reload_time", m_config.getSpecialConfigValue("image", "reload_time", k.c_str())},
|
||||
{"reload_cmd", m_config.getSpecialConfigValue("image", "reload_cmd", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("image", "zindex", k.c_str())},
|
||||
SHADOWABLE("image"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
keys = m_config.listKeysForSpecialCategory("input-field");
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "input-field",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("input-field", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"size", m_config.getSpecialConfigValue("input-field", "size", k.c_str())},
|
||||
{"inner_color", m_config.getSpecialConfigValue("input-field", "inner_color", k.c_str())},
|
||||
{"outer_color", m_config.getSpecialConfigValue("input-field", "outer_color", k.c_str())},
|
||||
{"outline_thickness", m_config.getSpecialConfigValue("input-field", "outline_thickness", k.c_str())},
|
||||
{"dots_size", m_config.getSpecialConfigValue("input-field", "dots_size", k.c_str())},
|
||||
{"dots_spacing", m_config.getSpecialConfigValue("input-field", "dots_spacing", k.c_str())},
|
||||
{"dots_center", m_config.getSpecialConfigValue("input-field", "dots_center", k.c_str())},
|
||||
{"dots_rounding", m_config.getSpecialConfigValue("input-field", "dots_rounding", k.c_str())},
|
||||
{"dots_text_format", m_config.getSpecialConfigValue("input-field", "dots_text_format", k.c_str())},
|
||||
{"fade_on_empty", m_config.getSpecialConfigValue("input-field", "fade_on_empty", k.c_str())},
|
||||
{"fade_timeout", m_config.getSpecialConfigValue("input-field", "fade_timeout", k.c_str())},
|
||||
{"font_color", m_config.getSpecialConfigValue("input-field", "font_color", k.c_str())},
|
||||
{"font_family", m_config.getSpecialConfigValue("input-field", "font_family", k.c_str())},
|
||||
{"halign", m_config.getSpecialConfigValue("input-field", "halign", k.c_str())},
|
||||
{"valign", m_config.getSpecialConfigValue("input-field", "valign", k.c_str())},
|
||||
{"position", m_config.getSpecialConfigValue("input-field", "position", k.c_str())},
|
||||
{"placeholder_text", m_config.getSpecialConfigValue("input-field", "placeholder_text", k.c_str())},
|
||||
{"hide_input", m_config.getSpecialConfigValue("input-field", "hide_input", k.c_str())},
|
||||
{"hide_input_base_color", m_config.getSpecialConfigValue("input-field", "hide_input_base_color", k.c_str())},
|
||||
{"rounding", m_config.getSpecialConfigValue("input-field", "rounding", k.c_str())},
|
||||
{"check_color", m_config.getSpecialConfigValue("input-field", "check_color", k.c_str())},
|
||||
{"fail_color", m_config.getSpecialConfigValue("input-field", "fail_color", k.c_str())},
|
||||
{"fail_text", m_config.getSpecialConfigValue("input-field", "fail_text", k.c_str())},
|
||||
{"capslock_color", m_config.getSpecialConfigValue("input-field", "capslock_color", k.c_str())},
|
||||
{"numlock_color", m_config.getSpecialConfigValue("input-field", "numlock_color", k.c_str())},
|
||||
{"bothlock_color", m_config.getSpecialConfigValue("input-field", "bothlock_color", k.c_str())},
|
||||
{"invert_numlock", m_config.getSpecialConfigValue("input-field", "invert_numlock", k.c_str())},
|
||||
{"swap_font_color", m_config.getSpecialConfigValue("input-field", "swap_font_color", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("input-field", "zindex", k.c_str())},
|
||||
SHADOWABLE("input-field"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
keys = m_config.listKeysForSpecialCategory("label");
|
||||
for (auto& k : keys) {
|
||||
// clang-format off
|
||||
result.push_back(CConfigManager::SWidgetConfig{
|
||||
.type = "label",
|
||||
.monitor = std::any_cast<Hyprlang::STRING>(m_config.getSpecialConfigValue("label", "monitor", k.c_str())),
|
||||
.values = {
|
||||
{"position", m_config.getSpecialConfigValue("label", "position", k.c_str())},
|
||||
{"color", m_config.getSpecialConfigValue("label", "color", k.c_str())},
|
||||
{"font_size", m_config.getSpecialConfigValue("label", "font_size", k.c_str())},
|
||||
{"font_family", m_config.getSpecialConfigValue("label", "font_family", k.c_str())},
|
||||
{"text", m_config.getSpecialConfigValue("label", "text", k.c_str())},
|
||||
{"halign", m_config.getSpecialConfigValue("label", "halign", k.c_str())},
|
||||
{"valign", m_config.getSpecialConfigValue("label", "valign", k.c_str())},
|
||||
{"rotate", m_config.getSpecialConfigValue("label", "rotate", k.c_str())},
|
||||
{"text_align", m_config.getSpecialConfigValue("label", "text_align", k.c_str())},
|
||||
{"zindex", m_config.getSpecialConfigValue("label", "zindex", k.c_str())},
|
||||
SHADOWABLE("label"),
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::optional<std::string> CConfigManager::handleSource(const std::string& command, const std::string& rawpath) {
|
||||
if (rawpath.length() < 2) {
|
||||
Debug::log(ERR, "source= path garbage");
|
||||
return "source path " + rawpath + " bogus!";
|
||||
}
|
||||
std::unique_ptr<glob_t, void (*)(glob_t*)> glob_buf{new glob_t, [](glob_t* g) { globfree(g); }};
|
||||
memset(glob_buf.get(), 0, sizeof(glob_t));
|
||||
|
||||
const auto CURRENTDIR = std::filesystem::path(configCurrentPath).parent_path().string();
|
||||
|
||||
if (auto r = glob(absolutePath(rawpath, CURRENTDIR).c_str(), GLOB_TILDE, nullptr, glob_buf.get()); r != 0) {
|
||||
std::string err = std::format("source= globbing error: {}", r == GLOB_NOMATCH ? "found no match" : GLOB_ABORTED ? "read error" : "out of memory");
|
||||
Debug::log(ERR, "{}", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < glob_buf->gl_pathc; i++) {
|
||||
const auto PATH = absolutePath(glob_buf->gl_pathv[i], CURRENTDIR);
|
||||
|
||||
if (PATH.empty() || PATH == configCurrentPath) {
|
||||
Debug::log(WARN, "source= skipping invalid path");
|
||||
continue;
|
||||
}
|
||||
std::unique_ptr<glob_t, void (*)(glob_t*)> glob_buf{new glob_t, [](glob_t* g) { globfree(g); }};
|
||||
memset(glob_buf.get(), 0, sizeof(glob_t));
|
||||
|
||||
const auto CURRENTDIR = std::filesystem::path(configCurrentPath).parent_path().string();
|
||||
|
||||
if (auto r = glob(absolutePath(rawpath, CURRENTDIR).c_str(), GLOB_TILDE, nullptr, glob_buf.get()); r != 0) {
|
||||
std::string err = std::format("source= globbing error: {}", r == GLOB_NOMATCH ? "found no match" : GLOB_ABORTED ? "read error" : "out of memory");
|
||||
Debug::log(ERR, "{}", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < glob_buf->gl_pathc; i++) {
|
||||
const auto PATH = absolutePath(glob_buf->gl_pathv[i], CURRENTDIR);
|
||||
|
||||
if (PATH.empty() || PATH == configCurrentPath) {
|
||||
Debug::log(WARN, "source= skipping invalid path");
|
||||
|
||||
if (!std::filesystem::is_regular_file(PATH)) {
|
||||
if (std::filesystem::exists(PATH)) {
|
||||
Debug::log(WARN, "source= skipping non-file {}", PATH);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!std::filesystem::is_regular_file(PATH)) {
|
||||
if (std::filesystem::exists(PATH)) {
|
||||
Debug::log(WARN, "source= skipping non-file {}", PATH);
|
||||
continue;
|
||||
}
|
||||
|
||||
Debug::log(ERR, "source= file doesnt exist");
|
||||
return "source file " + PATH + " doesn't exist!";
|
||||
}
|
||||
|
||||
// allow for nested config parsing
|
||||
auto backupConfigPath = configCurrentPath;
|
||||
configCurrentPath = PATH;
|
||||
|
||||
m_config.parseFile(PATH.c_str());
|
||||
|
||||
configCurrentPath = backupConfigPath;
|
||||
|
||||
Debug::log(ERR, "source= file doesnt exist");
|
||||
return "source file " + PATH + " doesn't exist!";
|
||||
}
|
||||
|
||||
|
||||
// allow for nested config parsing
|
||||
auto backupConfigPath = configCurrentPath;
|
||||
configCurrentPath = PATH;
|
||||
|
||||
m_config.parseFile(PATH.c_str());
|
||||
|
||||
configCurrentPath = backupConfigPath;
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::string> CConfigManager::handleBezier(const std::string& command, const std::string& args) {
|
||||
const auto ARGS = CVarList(args);
|
||||
|
||||
std::string bezierName = ARGS[0];
|
||||
|
||||
if (ARGS[1] == "")
|
||||
return "too few arguments";
|
||||
float p1x = std::stof(ARGS[1]);
|
||||
|
||||
if (ARGS[2] == "")
|
||||
return "too few arguments";
|
||||
float p1y = std::stof(ARGS[2]);
|
||||
|
||||
if (ARGS[3] == "")
|
||||
return "too few arguments";
|
||||
float p2x = std::stof(ARGS[3]);
|
||||
|
||||
if (ARGS[4] == "")
|
||||
return "too few arguments";
|
||||
float p2y = std::stof(ARGS[4]);
|
||||
|
||||
if (ARGS[5] != "")
|
||||
return "too many arguments";
|
||||
|
||||
g_pAnimationManager->addBezierWithName(bezierName, Vector2D(p1x, p1y), Vector2D(p2x, p2y));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::string> CConfigManager::handleAnimation(const std::string& command, const std::string& args) {
|
||||
const auto ARGS = CVarList(args);
|
||||
|
||||
const auto ANIMNAME = ARGS[0];
|
||||
|
||||
if (!m_AnimationTree.nodeExists(ANIMNAME))
|
||||
return "no such animation";
|
||||
|
||||
// This helper casts strings like "1", "true", "off", "yes"... to int.
|
||||
int64_t enabledInt = configStringToInt(ARGS[1]);
|
||||
|
||||
// Checking that the int is 1 or 0 because the helper can return integers out of range.
|
||||
if (enabledInt > 1 || enabledInt < 0)
|
||||
return "invalid animation on/off state";
|
||||
|
||||
if (!enabledInt) {
|
||||
m_AnimationTree.setConfigForNode(ANIMNAME, 0, 1, "default");
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::string> CConfigManager::handleBezier(const std::string& command, const std::string& args) {
|
||||
const auto ARGS = CVarList(args);
|
||||
|
||||
std::string bezierName = ARGS[0];
|
||||
|
||||
if (ARGS[1] == "")
|
||||
return "too few arguments";
|
||||
float p1x = std::stof(ARGS[1]);
|
||||
|
||||
if (ARGS[2] == "")
|
||||
return "too few arguments";
|
||||
float p1y = std::stof(ARGS[2]);
|
||||
|
||||
if (ARGS[3] == "")
|
||||
return "too few arguments";
|
||||
float p2x = std::stof(ARGS[3]);
|
||||
|
||||
if (ARGS[4] == "")
|
||||
return "too few arguments";
|
||||
float p2y = std::stof(ARGS[4]);
|
||||
|
||||
if (ARGS[5] != "")
|
||||
return "too many arguments";
|
||||
|
||||
g_pAnimationManager->addBezierWithName(bezierName, Vector2D(p1x, p1y), Vector2D(p2x, p2y));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<std::string> CConfigManager::handleAnimation(const std::string& command, const std::string& args) {
|
||||
const auto ARGS = CVarList(args);
|
||||
|
||||
const auto ANIMNAME = ARGS[0];
|
||||
|
||||
if (!m_AnimationTree.nodeExists(ANIMNAME))
|
||||
return "no such animation";
|
||||
|
||||
// This helper casts strings like "1", "true", "off", "yes"... to int.
|
||||
int64_t enabledInt = configStringToInt(ARGS[1]);
|
||||
|
||||
// Checking that the int is 1 or 0 because the helper can return integers out of range.
|
||||
if (enabledInt > 1 || enabledInt < 0)
|
||||
return "invalid animation on/off state";
|
||||
|
||||
if (!enabledInt) {
|
||||
m_AnimationTree.setConfigForNode(ANIMNAME, 0, 1, "default");
|
||||
return {};
|
||||
}
|
||||
|
||||
int64_t speed = -1;
|
||||
|
||||
// speed
|
||||
if (isNumber(ARGS[2], true)) {
|
||||
speed = std::stof(ARGS[2]);
|
||||
|
||||
if (speed <= 0) {
|
||||
speed = 1.f;
|
||||
return "invalid speed";
|
||||
}
|
||||
} else {
|
||||
speed = 10.f;
|
||||
|
||||
int64_t speed = -1;
|
||||
|
||||
// speed
|
||||
if (isNumber(ARGS[2], true)) {
|
||||
speed = std::stof(ARGS[2]);
|
||||
|
||||
if (speed <= 0) {
|
||||
speed = 1.f;
|
||||
return "invalid speed";
|
||||
}
|
||||
|
||||
std::string bezierName = ARGS[3];
|
||||
// ARGS[4] (style) currently usused by hyprlock
|
||||
m_AnimationTree.setConfigForNode(ANIMNAME, enabledInt, speed, bezierName, "");
|
||||
|
||||
if (!g_pAnimationManager->bezierExists(bezierName)) {
|
||||
const auto PANIMNODE = m_AnimationTree.getConfig(ANIMNAME);
|
||||
PANIMNODE->internalBezier = "default";
|
||||
return "no such bezier";
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
speed = 10.f;
|
||||
return "invalid speed";
|
||||
}
|
||||
|
||||
std::string bezierName = ARGS[3];
|
||||
// ARGS[4] (style) currently usused by hyprlock
|
||||
m_AnimationTree.setConfigForNode(ANIMNAME, enabledInt, speed, bezierName, "");
|
||||
|
||||
if (!g_pAnimationManager->bezierExists(bezierName)) {
|
||||
const auto PANIMNODE = m_AnimationTree.getConfig(ANIMNAME);
|
||||
PANIMNODE->internalBezier = "default";
|
||||
return "no such bezier";
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
49
src/main.cpp
49
src/main.cpp
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include "config/ConfigManager.hpp"
|
||||
#include "core/hyprlock.hpp"
|
||||
#include "helpers/Log.hpp"
|
||||
|
@ -93,30 +92,38 @@ int main(int argc, char** argv, char** envp) {
|
|||
}
|
||||
}
|
||||
|
||||
printVersion();
|
||||
g_pAnimationManager = makeUnique<CHyprlockAnimationManager>();
|
||||
|
||||
try {
|
||||
g_pConfigManager = makeUnique<CConfigManager>(configPath);
|
||||
g_pConfigManager->init();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "ConfigManager threw: {}", ex.what());
|
||||
if (std::string(ex.what()).contains("File does not exist"))
|
||||
Debug::log(NONE, " Make sure you have a config.");
|
||||
printVersion();
|
||||
g_pAnimationManager = makeUnique<CHyprlockAnimationManager>();
|
||||
|
||||
try {
|
||||
g_pConfigManager = makeUnique<CConfigManager>(configPath);
|
||||
g_pConfigManager->init();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "ConfigManager threw: {}", ex.what());
|
||||
if (std::string(ex.what()).contains("File does not exist"))
|
||||
Debug::log(NONE, " Make sure you have a config.");
|
||||
|
||||
throw; // Re-throw to outer catch
|
||||
}
|
||||
|
||||
if (noFadeIn)
|
||||
g_pConfigManager->m_AnimationTree.setConfigForNode("fadeIn", false, 0.f, "default");
|
||||
|
||||
try {
|
||||
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender);
|
||||
g_pHyprlock->run();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "Hyprlock threw: {}", ex.what());
|
||||
throw; // Re-throw to outer catch
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Unhandled exception in main: {}", e.what());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (noFadeIn)
|
||||
g_pConfigManager->m_AnimationTree.setConfigForNode("fadeIn", false, 0.f, "default");
|
||||
|
||||
try {
|
||||
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender);
|
||||
g_pHyprlock->run();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "Hyprlock threw: {}", ex.what());
|
||||
} catch (...) {
|
||||
Debug::log(ERR, "Unknown exception in main");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <chrono>
|
||||
#include <optional>
|
||||
#include <mutex> // Added for mpvpaperMutex
|
||||
#include "Shader.hpp"
|
||||
#include "../defines.hpp"
|
||||
#include "../core/LockSurface.hpp"
|
||||
|
@ -11,6 +12,8 @@
|
|||
#include "../config/ConfigDataValues.hpp"
|
||||
#include "widgets/IWidget.hpp"
|
||||
#include "Framebuffer.hpp"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
typedef std::unordered_map<OUTPUTID, std::vector<SP<IWidget>>> widgetMap_t;
|
||||
|
||||
|
@ -34,8 +37,13 @@ class CRenderer {
|
|||
void renderRect(const CBox& box, const CHyprColor& col, int rounding = 0);
|
||||
void renderBorder(const CBox& box, const CGradientValueData& gradient, int thickness, int rounding = 0, float alpha = 1.0);
|
||||
void renderTexture(const CBox& box, const CTexture& tex, float a = 1.0, int rounding = 0, std::optional<eTransform> tr = {});
|
||||
void renderTextureMix(const CBox& box, const CTexture& tex, const CTexture& tex2, float a = 1.0, float mixFactor = 0.0, int rounding = 0, std::optional<eTransform> tr = {});
|
||||
void blurFB(const CFramebuffer& outfb, SBlurParams params);
|
||||
void renderTextureMix(const CBox& box, const CTexture& tex, const CTexture& tex2, float a = 1.0, float mixFactor = 0.0, int rounding = 0, std::optional<eTransform> tr = {});
|
||||
void blurFB(const CFramebuffer& outfb, SBlurParams params);
|
||||
|
||||
// Added methods for layered rendering
|
||||
void renderBackground(const CSessionLockSurface& surf, float opacity);
|
||||
void renderShapes(const CSessionLockSurface& surf, float opacity);
|
||||
void renderInputFields(const CSessionLockSurface& surf, float opacity);
|
||||
|
||||
UP<CAsyncResourceGatherer> asyncResourceGatherer;
|
||||
std::chrono::system_clock::time_point firstFullFrameTime;
|
||||
|
@ -49,6 +57,10 @@ class CRenderer {
|
|||
void startFadeIn();
|
||||
void startFadeOut(bool unlock = false, bool immediate = true);
|
||||
|
||||
bool startMpvpaper(const std::string& monitor, const std::string& videoPath);
|
||||
void stopMpvpaper();
|
||||
void stopMpvpaper(const std::string& monitor);
|
||||
|
||||
private:
|
||||
widgetMap_t widgets;
|
||||
|
||||
|
@ -68,7 +80,11 @@ class CRenderer {
|
|||
|
||||
PHLANIMVAR<float> opacity;
|
||||
|
||||
std::map<std::string, pid_t> mpvpaperPids;
|
||||
std::map<std::string, std::string> mpvpaperVideoPaths;
|
||||
std::mutex mpvpaperMutex; // Added for safe PID management
|
||||
|
||||
std::vector<GLint> boundFBs;
|
||||
};
|
||||
|
||||
inline UP<CRenderer> g_pRenderer;
|
||||
inline UP<CRenderer> g_pRenderer;
|
|
@ -9,75 +9,297 @@
|
|||
#include <memory>
|
||||
#include <GLES3/gl32.h>
|
||||
|
||||
extern UP<CRenderer> g_pRenderer;
|
||||
|
||||
CBackground::~CBackground() {
|
||||
reset();
|
||||
if (isVideoBackground && !monitor.empty()) {
|
||||
g_pRenderer->stopMpvpaper(monitor);
|
||||
isVideoBackground = false;
|
||||
}
|
||||
}
|
||||
|
||||
void CBackground::registerSelf(const SP<CBackground>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
std::string CBackground::type() const {
|
||||
return "background";
|
||||
}
|
||||
|
||||
void CBackground::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
try {
|
||||
color = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
blurPasses = std::any_cast<Hyprlang::INT>(props.at("blur_passes"));
|
||||
blurSize = std::any_cast<Hyprlang::INT>(props.at("blur_size"));
|
||||
vibrancy = std::any_cast<Hyprlang::FLOAT>(props.at("vibrancy"));
|
||||
vibrancy_darkness = std::any_cast<Hyprlang::FLOAT>(props.at("vibrancy_darkness"));
|
||||
noise = std::any_cast<Hyprlang::FLOAT>(props.at("noise"));
|
||||
brightness = std::any_cast<Hyprlang::FLOAT>(props.at("brightness"));
|
||||
contrast = std::any_cast<Hyprlang::FLOAT>(props.at("contrast"));
|
||||
path = std::any_cast<Hyprlang::STRING>(props.at("path"));
|
||||
reloadCommand = std::any_cast<Hyprlang::STRING>(props.at("reload_cmd"));
|
||||
reloadTime = std::any_cast<Hyprlang::INT>(props.at("reload_time"));
|
||||
crossFadeTime = std::any_cast<Hyprlang::FLOAT>(props.at("crossfade_time"));
|
||||
reset();
|
||||
|
||||
} catch (const std::bad_any_cast& e) {
|
||||
RASSERT(false, "Failed to construct CBackground: {}", e.what());
|
||||
} catch (const std::out_of_range& e) {
|
||||
RASSERT(false, "Missing propperty for CBackground: {}", e.what());
|
||||
}
|
||||
// Parse properties
|
||||
if (props.contains("color")) {
|
||||
try {
|
||||
const auto& colorVal = props.at("color");
|
||||
if (colorVal.type() == typeid(Hyprlang::STRING)) {
|
||||
std::string colorStr = std::any_cast<Hyprlang::STRING>(colorVal);
|
||||
if (colorStr.starts_with("0x") || colorStr.starts_with("#"))
|
||||
colorStr = colorStr.substr(2);
|
||||
uint64_t colorValue = std::stoull(colorStr, nullptr, 16);
|
||||
color = CHyprColor(colorValue);
|
||||
} else if (colorVal.type() == typeid(Hyprlang::INT)) {
|
||||
uint64_t colorValue = std::any_cast<Hyprlang::INT>(colorVal);
|
||||
color = CHyprColor(colorValue);
|
||||
} else {
|
||||
throw std::bad_any_cast();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse color: {}", e.what());
|
||||
color = CHyprColor(0, 0, 0, 0); // Transparent default for video backgrounds
|
||||
}
|
||||
} else {
|
||||
color = CHyprColor(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
isScreenshot = path == "screenshot";
|
||||
blurPasses = 3;
|
||||
if (props.contains("blur_passes")) {
|
||||
try {
|
||||
const auto& val = props.at("blur_passes");
|
||||
if (val.type() == typeid(Hyprlang::INT)) {
|
||||
blurPasses = std::any_cast<Hyprlang::INT>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "blur_passes has unexpected type, using default: 3");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse blur_passes: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
blurSize = 10;
|
||||
if (props.contains("blur_size")) {
|
||||
try {
|
||||
const auto& val = props.at("blur_size");
|
||||
if (val.type() == typeid(Hyprlang::INT)) {
|
||||
blurSize = std::any_cast<Hyprlang::INT>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "blur_size has unexpected type, using default: 10");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse blur_size: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
vibrancy = 0.1696f;
|
||||
if (props.contains("vibrancy")) {
|
||||
try {
|
||||
const auto& val = props.at("vibrancy");
|
||||
if (val.type() == typeid(Hyprlang::FLOAT)) {
|
||||
vibrancy = std::any_cast<Hyprlang::FLOAT>(val);
|
||||
} else if (val.type() == typeid(Hyprlang::INT)) {
|
||||
vibrancy = static_cast<float>(std::any_cast<Hyprlang::INT>(val));
|
||||
} else {
|
||||
Debug::log(WARN, "vibrancy has unexpected type, using default: 0.1696");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse vibrancy: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
vibrancy_darkness = 0.f;
|
||||
if (props.contains("vibrancy_darkness")) {
|
||||
try {
|
||||
const auto& val = props.at("vibrancy_darkness");
|
||||
if (val.type() == typeid(Hyprlang::FLOAT)) {
|
||||
vibrancy_darkness = std::any_cast<Hyprlang::FLOAT>(val);
|
||||
} else if (val.type() == typeid(Hyprlang::INT)) {
|
||||
vibrancy_darkness = static_cast<float>(std::any_cast<Hyprlang::INT>(val));
|
||||
} else {
|
||||
Debug::log(WARN, "vibrancy_darkness has unexpected type, using default: 0");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse vibrancy_darkness: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
noise = 0.0117f;
|
||||
if (props.contains("noise")) {
|
||||
try {
|
||||
const auto& val = props.at("noise");
|
||||
if (val.type() == typeid(Hyprlang::FLOAT)) {
|
||||
noise = std::any_cast<Hyprlang::FLOAT>(val);
|
||||
} else if (val.type() == typeid(Hyprlang::INT)) {
|
||||
noise = static_cast<float>(std::any_cast<Hyprlang::INT>(val));
|
||||
} else {
|
||||
Debug::log(WARN, "noise has unexpected type, using default: 0.0117");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse noise: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
brightness = 0.8172f;
|
||||
if (props.contains("brightness")) {
|
||||
try {
|
||||
const auto& val = props.at("brightness");
|
||||
if (val.type() == typeid(Hyprlang::FLOAT)) {
|
||||
brightness = std::any_cast<Hyprlang::FLOAT>(val);
|
||||
} else if (val.type() == typeid(Hyprlang::INT)) {
|
||||
brightness = static_cast<float>(std::any_cast<Hyprlang::INT>(val));
|
||||
} else {
|
||||
Debug::log(WARN, "brightness has unexpected type, using default: 0.8172");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse brightness: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
contrast = 0.8916f;
|
||||
if (props.contains("contrast")) {
|
||||
try {
|
||||
const auto& val = props.at("contrast");
|
||||
if (val.type() == typeid(Hyprlang::FLOAT)) {
|
||||
contrast = std::any_cast<Hyprlang::FLOAT>(val);
|
||||
} else if (val.type() == typeid(Hyprlang::INT)) {
|
||||
contrast = static_cast<float>(std::any_cast<Hyprlang::INT>(val));
|
||||
} else {
|
||||
Debug::log(WARN, "contrast has unexpected type, using default: 0.8916");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse contrast: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
path = "";
|
||||
if (props.contains("path")) {
|
||||
try {
|
||||
const auto& val = props.at("path");
|
||||
if (val.type() == typeid(Hyprlang::STRING)) {
|
||||
path = std::any_cast<Hyprlang::STRING>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "path has unexpected type, using default: empty");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse path: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
reloadCommand = "";
|
||||
if (props.contains("reload_cmd")) {
|
||||
try {
|
||||
const auto& val = props.at("reload_cmd");
|
||||
if (val.type() == typeid(Hyprlang::STRING)) {
|
||||
reloadCommand = std::any_cast<Hyprlang::STRING>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "reload_cmd has unexpected type, using default: empty");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse reload_cmd: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
reloadTime = -1;
|
||||
if (props.contains("reload_time")) {
|
||||
try {
|
||||
const auto& val = props.at("reload_time");
|
||||
if (val.type() == typeid(Hyprlang::INT)) {
|
||||
reloadTime = std::any_cast<Hyprlang::INT>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "reload_time has unexpected type, using default: -1");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse reload_time: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
crossFadeTime = -1.f;
|
||||
if (props.contains("crossfade_time")) {
|
||||
try {
|
||||
const auto& val = props.at("crossfade_time");
|
||||
if (val.type() == typeid(Hyprlang::FLOAT)) {
|
||||
crossFadeTime = std::any_cast<Hyprlang::FLOAT>(val);
|
||||
} else if (val.type() == typeid(Hyprlang::INT)) {
|
||||
crossFadeTime = static_cast<float>(std::any_cast<Hyprlang::INT>(val));
|
||||
} else {
|
||||
Debug::log(WARN, "crossfade_time has unexpected type, using default: -1");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse crossfade_time: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
fallbackPath = "";
|
||||
if (props.contains("fallback_path")) {
|
||||
try {
|
||||
const auto& val = props.at("fallback_path");
|
||||
if (val.type() == typeid(Hyprlang::STRING)) {
|
||||
fallbackPath = std::any_cast<Hyprlang::STRING>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "fallback_path has unexpected type, using default: empty");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse fallback_path: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
isScreenshot = path == "screenshot";
|
||||
monitor = pOutput->stringPort;
|
||||
std::string type = "image";
|
||||
if (props.contains("type")) {
|
||||
try {
|
||||
const auto& val = props.at("type");
|
||||
if (val.type() == typeid(Hyprlang::STRING)) {
|
||||
type = std::any_cast<Hyprlang::STRING>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "type has unexpected type, using default: image");
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Failed to parse type: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the path is an MP4 file
|
||||
if (path.ends_with(".mp4")) {
|
||||
isVideoBackground = true;
|
||||
videoPath = path;
|
||||
Debug::log(LOG, "Detected video background: {}", path);
|
||||
resourceID = ""; // Skip loading a static texture since we'll use mpvpaper
|
||||
} else {
|
||||
isVideoBackground = false;
|
||||
videoPath = "";
|
||||
resourceID = isScreenshot ? CScreencopyFrame::getResourceId(pOutput) : (!path.empty() ? "background:" + path : "");
|
||||
}
|
||||
|
||||
viewport = pOutput->getViewport();
|
||||
outputPort = pOutput->stringPort;
|
||||
transform = isScreenshot ? wlTransformToHyprutils(invertTransform(pOutput->transform)) : HYPRUTILS_TRANSFORM_NORMAL;
|
||||
|
||||
if (isScreenshot && !isVideoBackground) {
|
||||
// When the initial gather of the asyncResourceGatherer is completed (ready), all DMAFrames are available.
|
||||
// Dynamic ones are tricky, because a screencopy would copy hyprlock itself.
|
||||
if (g_pRenderer->asyncResourceGatherer->gathered) {
|
||||
if (!g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID))
|
||||
resourceID = ""; // Fallback to solid color (background:color)
|
||||
resourceID = "";
|
||||
if (type == "video" || path.ends_with(".mp4")) {
|
||||
videoPath = path;
|
||||
Debug::log(LOG, "Detected video background: {}", path);
|
||||
if (!path.empty()) {
|
||||
Debug::log(LOG, "Attempting to start mpvpaper for monitor {} with video {}", monitor, path);
|
||||
bool mpvSuccess = g_pRenderer->startMpvpaper(monitor, path);
|
||||
isVideoBackground = mpvSuccess;
|
||||
if (!mpvSuccess) {
|
||||
if (!fallbackPath.empty() && !fallbackPath.ends_with(".mp4")) {
|
||||
Debug::log(LOG, "Video background failed, using fallback: {}", fallbackPath);
|
||||
resourceID = "background:" + fallbackPath;
|
||||
} else {
|
||||
Debug::log(ERR, "Video background failed and no valid fallback path provided, using transparent.");
|
||||
resourceID = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resourceID = isScreenshot ? CScreencopyFrame::getResourceId(pOutput) : (!path.empty() && !path.ends_with(".mp4") ? "background:" + path : "");
|
||||
}
|
||||
|
||||
if (!g_pHyprlock->getScreencopy()) {
|
||||
Debug::log(ERR, "No screencopy support! path=screenshot won't work. Falling back to background color.");
|
||||
resourceID = "";
|
||||
viewport = pOutput->getViewport();
|
||||
outputPort = pOutput->stringPort;
|
||||
transform = isScreenshot ? wlTransformToHyprutils(invertTransform(pOutput->transform)) : HYPRUTILS_TRANSFORM_NORMAL;
|
||||
|
||||
if (isScreenshot && !isVideoBackground) {
|
||||
if (g_pRenderer->asyncResourceGatherer->gathered) {
|
||||
if (!g_pRenderer->asyncResourceGatherer->getAssetByID(resourceID))
|
||||
resourceID = "";
|
||||
}
|
||||
if (!g_pHyprlock->getScreencopy()) {
|
||||
Debug::log(ERR, "No screencopy support! path=screenshot won't work. Falling back to transparent.");
|
||||
resourceID = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isScreenshot && !isVideoBackground && reloadTime > -1) {
|
||||
try {
|
||||
modificationTime = std::filesystem::last_write_time(absolutePath(path, ""));
|
||||
} catch (std::exception& e) { Debug::log(ERR, "{}", e.what()); }
|
||||
|
||||
plantReloadTimer(); // No reloads for screenshots or videos
|
||||
if (!isScreenshot && !isVideoBackground && reloadTime > -1) {
|
||||
try {
|
||||
modificationTime = std::filesystem::last_write_time(absolutePath(path, ""));
|
||||
} catch (std::exception& e) { Debug::log(ERR, "{}", e.what()); }
|
||||
plantReloadTimer();
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "Exception in CBackground::configure: {}", e.what());
|
||||
isVideoBackground = false;
|
||||
resourceID = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +308,6 @@ void CBackground::reset() {
|
|||
reloadTimer->cancel();
|
||||
reloadTimer.reset();
|
||||
}
|
||||
|
||||
if (fade) {
|
||||
if (fade->crossFadeTimer) {
|
||||
fade->crossFadeTimer->cancel();
|
||||
|
@ -97,32 +318,14 @@ void CBackground::reset() {
|
|||
}
|
||||
|
||||
void CBackground::renderRect(CHyprColor color) {
|
||||
CBox monbox = {0, 0, viewport.x, viewport.y};
|
||||
CBox monbox = {0, 0, (int)viewport.x, (int)viewport.y};
|
||||
g_pRenderer->renderRect(monbox, color, 0);
|
||||
}
|
||||
|
||||
static void onReloadTimer(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG) {
|
||||
PBG->onReloadTimerUpdate();
|
||||
PBG->plantReloadTimer();
|
||||
}
|
||||
}
|
||||
|
||||
static void onCrossFadeTimer(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG)
|
||||
PBG->onCrossFadeTimerUpdate();
|
||||
}
|
||||
|
||||
static void onAssetCallback(WP<CBackground> ref) {
|
||||
if (auto PBG = ref.lock(); PBG)
|
||||
PBG->startCrossFadeOrUpdateRender();
|
||||
}
|
||||
|
||||
bool CBackground::draw(const SRenderData& data) {
|
||||
if (isVideoBackground) {
|
||||
// Skip rendering the static background since mpvpaper is handling the video
|
||||
Debug::log(LOG, "Skipping static background rendering; using video background via mpvpaper");
|
||||
return false;
|
||||
return false; // mpvpaper handles rendering
|
||||
}
|
||||
|
||||
if (resourceID.empty()) {
|
||||
|
@ -152,15 +355,13 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
if (firstRender)
|
||||
firstRender = false;
|
||||
|
||||
// make it brah
|
||||
Vector2D size = asset->texture.m_vSize;
|
||||
if (transform % 2 == 1 && isScreenshot) {
|
||||
size.x = asset->texture.m_vSize.y;
|
||||
size.y = asset->texture.m_vSize.x;
|
||||
}
|
||||
|
||||
CBox texbox = {{}, size};
|
||||
|
||||
CBox texbox = {{}, size};
|
||||
float scaleX = viewport.x / size.x;
|
||||
float scaleY = viewport.y / size.y;
|
||||
|
||||
|
@ -174,7 +375,7 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
texbox.round();
|
||||
|
||||
if (!blurredFB.isAllocated())
|
||||
blurredFB.alloc(viewport.x, viewport.y); // TODO 10 bit
|
||||
blurredFB.alloc((int)viewport.x, (int)viewport.y);
|
||||
|
||||
blurredFB.bind();
|
||||
|
||||
|
@ -187,12 +388,12 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
|
||||
if (blurPasses > 0)
|
||||
g_pRenderer->blurFB(blurredFB,
|
||||
CRenderer::SBlurParams{.size = blurSize,
|
||||
.passes = blurPasses,
|
||||
.noise = noise,
|
||||
.contrast = contrast,
|
||||
.brightness = brightness,
|
||||
.vibrancy = vibrancy,
|
||||
CRenderer::SBlurParams{.size = blurSize,
|
||||
.passes = blurPasses,
|
||||
.noise = noise,
|
||||
.contrast = contrast,
|
||||
.brightness = brightness,
|
||||
.vibrancy = vibrancy,
|
||||
.vibrancy_darkness = vibrancy_darkness});
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
@ -200,7 +401,6 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
CTexture* tex = blurredFB.isAllocated() ? &blurredFB.m_cTex : &asset->texture;
|
||||
|
||||
CBox texbox = {{}, tex->m_vSize};
|
||||
|
||||
Vector2D size = tex->m_vSize;
|
||||
float scaleX = viewport.x / tex->m_vSize.x;
|
||||
float scaleY = viewport.y / tex->m_vSize.y;
|
||||
|
@ -215,52 +415,31 @@ bool CBackground::draw(const SRenderData& data) {
|
|||
texbox.round();
|
||||
g_pRenderer->renderTexture(texbox, *tex, data.opacity, 0, HYPRUTILS_TRANSFORM_FLIPPED_180);
|
||||
|
||||
return fade || data.opacity < 1.0; // actively render during fading
|
||||
return fade || data.opacity < 1.0;
|
||||
}
|
||||
|
||||
void CBackground::plantReloadTimer() {
|
||||
if (reloadTime == 0)
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::hours(1), [REF = m_self](auto, auto) { onReloadTimer(REF); }, nullptr, true);
|
||||
else if (reloadTime > 0)
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime), [REF = m_self](auto, auto) { onReloadTimer(REF); }, nullptr, true);
|
||||
}
|
||||
|
||||
void CBackground::onCrossFadeTimerUpdate() {
|
||||
// Animation done: Unload previous asset, deinitialize the fade and pass the asset
|
||||
if (fade) {
|
||||
fade->crossFadeTimer.reset();
|
||||
fade.reset();
|
||||
}
|
||||
|
||||
if (blurPasses <= 0 && !isScreenshot)
|
||||
blurredFB.release();
|
||||
|
||||
asset = pendingAsset;
|
||||
resourceID = pendingResourceID;
|
||||
pendingResourceID = "";
|
||||
pendingAsset = nullptr;
|
||||
firstRender = true;
|
||||
|
||||
g_pHyprlock->renderOutput(outputPort);
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::hours(1),
|
||||
[REF = m_self](std::shared_ptr<CTimer>, void*) { REF.lock()->onReloadTimerUpdate(); }, nullptr, true);
|
||||
else if (reloadTime > -1)
|
||||
reloadTimer = g_pHyprlock->addTimer(std::chrono::seconds(reloadTime),
|
||||
[REF = m_self](std::shared_ptr<CTimer>, void*) { REF.lock()->onReloadTimerUpdate(); }, nullptr, true);
|
||||
}
|
||||
|
||||
void CBackground::onReloadTimerUpdate() {
|
||||
const std::string OLDPATH = path;
|
||||
|
||||
// Path parsing and early returns
|
||||
if (!reloadCommand.empty()) {
|
||||
path = g_pHyprlock->spawnSync(reloadCommand);
|
||||
|
||||
if (path.ends_with('\n'))
|
||||
path.pop_back();
|
||||
|
||||
if (path.starts_with("file://"))
|
||||
path = path.substr(7);
|
||||
|
||||
if (path.empty())
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip reload for video backgrounds
|
||||
if (isVideoBackground)
|
||||
return;
|
||||
|
||||
|
@ -268,7 +447,6 @@ void CBackground::onReloadTimerUpdate() {
|
|||
const auto MTIME = std::filesystem::last_write_time(absolutePath(path, ""));
|
||||
if (OLDPATH == path && MTIME == modificationTime)
|
||||
return;
|
||||
|
||||
modificationTime = MTIME;
|
||||
} catch (std::exception& e) {
|
||||
path = OLDPATH;
|
||||
|
@ -279,17 +457,33 @@ void CBackground::onReloadTimerUpdate() {
|
|||
if (!pendingResourceID.empty())
|
||||
return;
|
||||
|
||||
// Issue the next request
|
||||
request.id = std::string{"background:"} + path + ",time:" + std::to_string((uint64_t)modificationTime.time_since_epoch().count());
|
||||
request.id = std::string{"background:"} + path + ",time:" + std::to_string((uint64_t)modificationTime.time_since_epoch().count());
|
||||
pendingResourceID = request.id;
|
||||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
|
||||
request.callback = [REF = m_self]() { REF.lock()->startCrossFadeOrUpdateRender(); };
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
||||
void CBackground::onCrossFadeTimerUpdate() {
|
||||
if (fade) {
|
||||
fade->crossFadeTimer.reset();
|
||||
fade.reset();
|
||||
}
|
||||
|
||||
if (blurPasses <= 0 && !isScreenshot)
|
||||
blurredFB.release();
|
||||
|
||||
asset = pendingAsset;
|
||||
resourceID = pendingResourceID;
|
||||
pendingResourceID = "";
|
||||
pendingAsset = nullptr;
|
||||
firstRender = true;
|
||||
|
||||
g_pHyprlock->renderOutput(outputPort);
|
||||
}
|
||||
|
||||
void CBackground::startCrossFadeOrUpdateRender() {
|
||||
auto newAsset = g_pRenderer->asyncResourceGatherer->getAssetByID(pendingResourceID);
|
||||
if (newAsset) {
|
||||
|
@ -299,27 +493,27 @@ void CBackground::startCrossFadeOrUpdateRender() {
|
|||
} else if (resourceID != pendingResourceID) {
|
||||
pendingAsset = newAsset;
|
||||
if (crossFadeTime > 0) {
|
||||
// Start a fade
|
||||
if (!fade)
|
||||
fade = makeUnique<SFade>(std::chrono::system_clock::now(), 0, nullptr);
|
||||
fade = makeUnique<SFade>();
|
||||
else {
|
||||
// Maybe we were already fading so reset it just in case, but shouldn't be happening.
|
||||
if (fade->crossFadeTimer) {
|
||||
fade->crossFadeTimer->cancel();
|
||||
fade->crossFadeTimer.reset();
|
||||
}
|
||||
}
|
||||
fade->start = std::chrono::system_clock::now();
|
||||
fade->a = 0;
|
||||
fade->a = 0;
|
||||
fade->crossFadeTimer =
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds((int)(1000.0 * crossFadeTime)), [REF = m_self](auto, auto) { onCrossFadeTimer(REF); }, nullptr);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds((int)(1000.0 * crossFadeTime)),
|
||||
[REF = m_self](std::shared_ptr<CTimer>, void*) { REF.lock()->onCrossFadeTimerUpdate(); }, nullptr, true);
|
||||
} else {
|
||||
onCrossFadeTimerUpdate();
|
||||
}
|
||||
}
|
||||
} else if (!pendingResourceID.empty()) {
|
||||
Debug::log(WARN, "Asset {} not available after the asyncResourceGatherer's callback!", pendingResourceID);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100), [REF = m_self](auto, auto) { onAssetCallback(REF); }, nullptr);
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(100),
|
||||
[REF = m_self](std::shared_ptr<CTimer>, void*) { REF.lock()->startCrossFadeOrUpdateRender(); }, nullptr, true);
|
||||
}
|
||||
|
||||
g_pHyprlock->renderOutput(outputPort);
|
||||
|
|
|
@ -29,8 +29,9 @@ class CBackground : public IWidget {
|
|||
|
||||
void registerSelf(const SP<CBackground>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) override;
|
||||
virtual bool draw(const SRenderData& data) override;
|
||||
virtual std::string type() const override; // Added for layered rendering
|
||||
|
||||
void reset(); // Unload assets, remove timers, etc.
|
||||
|
||||
|
@ -41,9 +42,11 @@ class CBackground : public IWidget {
|
|||
void plantReloadTimer();
|
||||
void startCrossFadeOrUpdateRender();
|
||||
|
||||
// New members for video background support
|
||||
// Members for video background support
|
||||
bool isVideoBackground = false;
|
||||
std::string videoPath;
|
||||
std::string monitor; // Store monitor name for mpvpaper
|
||||
std::string fallbackPath; // Added for fallback image if video fails
|
||||
|
||||
private:
|
||||
WP<CBackground> m_self;
|
||||
|
|
|
@ -17,7 +17,8 @@ class IWidget {
|
|||
virtual ~IWidget() = default;
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput) = 0;
|
||||
virtual bool draw(const SRenderData& data) = 0;
|
||||
virtual bool draw(const SRenderData& data) = 0;
|
||||
virtual std::string type() const = 0; // Added for layered rendering
|
||||
|
||||
static Vector2D posFromHVAlign(const Vector2D& viewport, const Vector2D& size, const Vector2D& offset, const std::string& halign, const std::string& valign,
|
||||
const double& ang = 0);
|
||||
|
@ -33,4 +34,4 @@ class IWidget {
|
|||
};
|
||||
|
||||
static SFormatResult formatString(std::string in);
|
||||
};
|
||||
};
|
|
@ -15,6 +15,10 @@ void CImage::registerSelf(const SP<CImage>& self) {
|
|||
m_self = self;
|
||||
}
|
||||
|
||||
std::string CImage::type() const {
|
||||
return "image";
|
||||
}
|
||||
|
||||
static void onTimer(WP<CImage> ref) {
|
||||
if (auto PIMAGE = ref.lock(); PIMAGE) {
|
||||
PIMAGE->onTimerUpdate();
|
||||
|
@ -32,13 +36,10 @@ void CImage::onTimerUpdate() {
|
|||
|
||||
if (!reloadCommand.empty()) {
|
||||
path = g_pHyprlock->spawnSync(reloadCommand);
|
||||
|
||||
if (path.ends_with('\n'))
|
||||
path.pop_back();
|
||||
|
||||
if (path.starts_with("file://"))
|
||||
path = path.substr(7);
|
||||
|
||||
if (path.empty())
|
||||
return;
|
||||
}
|
||||
|
@ -47,7 +48,6 @@ void CImage::onTimerUpdate() {
|
|||
const auto MTIME = std::filesystem::last_write_time(absolutePath(path, ""));
|
||||
if (OLDPATH == path && MTIME == modificationTime)
|
||||
return;
|
||||
|
||||
modificationTime = MTIME;
|
||||
} catch (std::exception& e) {
|
||||
path = OLDPATH;
|
||||
|
@ -58,17 +58,16 @@ void CImage::onTimerUpdate() {
|
|||
if (!pendingResourceID.empty())
|
||||
return;
|
||||
|
||||
request.id = std::string{"image:"} + path + ",time:" + std::to_string((uint64_t)modificationTime.time_since_epoch().count());
|
||||
request.id = std::string{"image:"} + path + ",time:" + std::to_string((uint64_t)modificationTime.time_since_epoch().count());
|
||||
pendingResourceID = request.id;
|
||||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
request.asset = path;
|
||||
request.type = CAsyncResourceGatherer::eTargetType::TARGET_IMAGE;
|
||||
request.callback = [REF = m_self]() { onAssetCallback(REF); };
|
||||
|
||||
g_pRenderer->asyncResourceGatherer->requestAsyncAssetPreload(request);
|
||||
}
|
||||
|
||||
void CImage::plantTimer() {
|
||||
|
||||
if (reloadTime == 0) {
|
||||
imageTimer = g_pHyprlock->addTimer(std::chrono::hours(1), [REF = m_self](auto, auto) { onTimer(REF); }, nullptr, true);
|
||||
} else if (reloadTime > 0)
|
||||
|
@ -83,32 +82,30 @@ void CImage::configure(const std::unordered_map<std::string, std::any>& props, c
|
|||
shadow.configure(m_self.lock(), props, viewport);
|
||||
|
||||
try {
|
||||
size = std::any_cast<Hyprlang::INT>(props.at("size"));
|
||||
size = std::any_cast<Hyprlang::INT>(props.at("size"));
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
|
||||
path = std::any_cast<Hyprlang::STRING>(props.at("path"));
|
||||
reloadTime = std::any_cast<Hyprlang::INT>(props.at("reload_time"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
path = std::any_cast<Hyprlang::STRING>(props.at("path"));
|
||||
reloadTime = std::any_cast<Hyprlang::INT>(props.at("reload_time"));
|
||||
reloadCommand = std::any_cast<Hyprlang::STRING>(props.at("reload_cmd"));
|
||||
} catch (const std::bad_any_cast& e) {
|
||||
RASSERT(false, "Failed to construct CImage: {}", e.what()); //
|
||||
RASSERT(false, "Failed to construct CImage: {}", e.what());
|
||||
} catch (const std::out_of_range& e) {
|
||||
RASSERT(false, "Missing propperty for CImage: {}", e.what()); //
|
||||
RASSERT(false, "Missing propperty for CImage: {}", e.what());
|
||||
}
|
||||
|
||||
resourceID = "image:" + path;
|
||||
angle = angle * M_PI / 180.0;
|
||||
angle = angle * M_PI / 180.0;
|
||||
|
||||
if (reloadTime > -1) {
|
||||
try {
|
||||
modificationTime = std::filesystem::last_write_time(absolutePath(path, ""));
|
||||
} catch (std::exception& e) { Debug::log(ERR, "{}", e.what()); }
|
||||
|
||||
plantTimer();
|
||||
}
|
||||
}
|
||||
|
@ -118,22 +115,17 @@ void CImage::reset() {
|
|||
imageTimer->cancel();
|
||||
imageTimer.reset();
|
||||
}
|
||||
|
||||
if (g_pHyprlock->m_bTerminate)
|
||||
return;
|
||||
|
||||
imageFB.release();
|
||||
|
||||
if (asset && reloadTime > -1) // Don't unload asset if it's a static image
|
||||
if (asset && reloadTime > -1)
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
|
||||
asset = nullptr;
|
||||
asset = nullptr;
|
||||
pendingResourceID = "";
|
||||
resourceID = "";
|
||||
resourceID = "";
|
||||
}
|
||||
|
||||
bool CImage::draw(const SRenderData& data) {
|
||||
|
||||
if (resourceID.empty())
|
||||
return false;
|
||||
|
||||
|
@ -150,27 +142,22 @@ bool CImage::draw(const SRenderData& data) {
|
|||
}
|
||||
|
||||
if (!imageFB.isAllocated()) {
|
||||
|
||||
const Vector2D IMAGEPOS = {border, border};
|
||||
const Vector2D IMAGEPOS = {border, border};
|
||||
const Vector2D BORDERPOS = {0.0, 0.0};
|
||||
const Vector2D TEXSIZE = asset->texture.m_vSize;
|
||||
const float SCALEX = size / TEXSIZE.x;
|
||||
const float SCALEY = size / TEXSIZE.y;
|
||||
const Vector2D TEXSIZE = asset->texture.m_vSize;
|
||||
const float SCALEX = size / TEXSIZE.x;
|
||||
const float SCALEY = size / TEXSIZE.y;
|
||||
|
||||
// image with borders offset, with extra pixel for anti-aliasing when rotated
|
||||
CBox texbox = {angle == 0 ? IMAGEPOS : IMAGEPOS + Vector2D{1.0, 1.0}, TEXSIZE};
|
||||
|
||||
texbox.w *= std::max(SCALEX, SCALEY);
|
||||
texbox.h *= std::max(SCALEX, SCALEY);
|
||||
|
||||
// plus borders if any
|
||||
CBox borderBox = {angle == 0 ? BORDERPOS : BORDERPOS + Vector2D{1.0, 1.0}, texbox.size() + IMAGEPOS * 2.0};
|
||||
|
||||
borderBox.round();
|
||||
|
||||
const Vector2D FBSIZE = angle == 0 ? borderBox.size() : borderBox.size() + Vector2D{2.0, 2.0};
|
||||
const int ROUND = roundingForBox(texbox, rounding);
|
||||
const int BORDERROUND = roundingForBorderBox(borderBox, rounding, border);
|
||||
const Vector2D FBSIZE = angle == 0 ? borderBox.size() : borderBox.size() + Vector2D{2.0, 2.0};
|
||||
const int ROUND = roundingForBox(texbox, rounding);
|
||||
const int BORDERROUND = roundingForBorderBox(borderBox, rounding, border);
|
||||
|
||||
imageFB.alloc(FBSIZE.x, FBSIZE.y, true);
|
||||
g_pRenderer->pushFb(imageFB.m_iFb);
|
||||
|
@ -185,8 +172,8 @@ bool CImage::draw(const SRenderData& data) {
|
|||
g_pRenderer->popFb();
|
||||
}
|
||||
|
||||
CTexture* tex = &imageFB.m_cTex;
|
||||
CBox texbox = {{}, tex->m_vSize};
|
||||
CTexture* tex = &imageFB.m_cTex;
|
||||
CBox texbox = {{}, tex->m_vSize};
|
||||
|
||||
if (firstRender) {
|
||||
firstRender = false;
|
||||
|
@ -196,7 +183,6 @@ bool CImage::draw(const SRenderData& data) {
|
|||
shadow.draw(data);
|
||||
|
||||
const auto TEXPOS = posFromHVAlign(viewport, tex->m_vSize, pos, halign, valign, angle);
|
||||
|
||||
texbox.x = TEXPOS.x;
|
||||
texbox.y = TEXPOS.y;
|
||||
|
||||
|
@ -215,9 +201,8 @@ void CImage::renderUpdate() {
|
|||
} else if (resourceID != pendingResourceID) {
|
||||
g_pRenderer->asyncResourceGatherer->unloadAsset(asset);
|
||||
imageFB.release();
|
||||
|
||||
asset = newAsset;
|
||||
resourceID = pendingResourceID;
|
||||
asset = newAsset;
|
||||
resourceID = pendingResourceID;
|
||||
firstRender = true;
|
||||
}
|
||||
pendingResourceID = "";
|
||||
|
@ -231,4 +216,4 @@ void CImage::renderUpdate() {
|
|||
}
|
||||
|
||||
g_pHyprlock->renderOutput(output->stringPort);
|
||||
}
|
||||
}
|
|
@ -20,43 +20,39 @@ class CImage : public IWidget {
|
|||
CImage() = default;
|
||||
~CImage();
|
||||
|
||||
void registerSelf(const SP<CImage>& self);
|
||||
void registerSelf(const SP<CImage>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) override;
|
||||
virtual bool draw(const SRenderData& data) override;
|
||||
virtual std::string type() const override; // Added for layered rendering
|
||||
|
||||
void reset();
|
||||
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
void reset();
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
|
||||
private:
|
||||
WP<CImage> m_self;
|
||||
WP<CImage> m_self;
|
||||
|
||||
CFramebuffer imageFB;
|
||||
CFramebuffer imageFB;
|
||||
|
||||
int size;
|
||||
int rounding;
|
||||
double border;
|
||||
double angle;
|
||||
CGradientValueData color;
|
||||
Vector2D pos;
|
||||
|
||||
std::string halign, valign, path;
|
||||
|
||||
bool firstRender = true;
|
||||
|
||||
int reloadTime;
|
||||
std::string reloadCommand;
|
||||
std::filesystem::file_time_type modificationTime;
|
||||
std::shared_ptr<CTimer> imageTimer;
|
||||
int size;
|
||||
int rounding;
|
||||
double border;
|
||||
double angle;
|
||||
CGradientValueData color;
|
||||
Vector2D pos;
|
||||
std::string halign, valign, path;
|
||||
bool firstRender = true;
|
||||
int reloadTime;
|
||||
std::string reloadCommand;
|
||||
std::filesystem::file_time_type modificationTime;
|
||||
std::shared_ptr<CTimer> imageTimer;
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
|
||||
Vector2D viewport;
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID; // if reloading image
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
COutput* output = nullptr;
|
||||
CShadowable shadow;
|
||||
};
|
||||
Vector2D viewport;
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID; // if reloading image
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
COutput* output = nullptr;
|
||||
CShadowable shadow;
|
||||
};
|
|
@ -15,6 +15,10 @@ void CLabel::registerSelf(const SP<CLabel>& self) {
|
|||
m_self = self;
|
||||
}
|
||||
|
||||
std::string CLabel::type() const {
|
||||
return "label";
|
||||
}
|
||||
|
||||
static void onTimer(WP<CLabel> ref) {
|
||||
if (auto PLABEL = ref.lock(); PLABEL) {
|
||||
// update label
|
||||
|
@ -57,7 +61,6 @@ void CLabel::onTimerUpdate() {
|
|||
}
|
||||
|
||||
void CLabel::plantTimer() {
|
||||
|
||||
if (label.updateEveryMs != 0)
|
||||
labelTimer = g_pHyprlock->addTimer(std::chrono::milliseconds((int)label.updateEveryMs), [REF = m_self](auto, auto) { onTimer(REF); }, this, label.allowForceUpdate);
|
||||
else if (label.updateEveryMs == 0 && label.allowForceUpdate)
|
||||
|
@ -171,4 +174,4 @@ void CLabel::renderUpdate() {
|
|||
}
|
||||
|
||||
g_pHyprlock->renderOutput(outputStringPort);
|
||||
}
|
||||
}
|
|
@ -17,40 +17,38 @@ class CLabel : public IWidget {
|
|||
CLabel() = default;
|
||||
~CLabel();
|
||||
|
||||
void registerSelf(const SP<CLabel>& self);
|
||||
void registerSelf(const SP<CLabel>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput) override;
|
||||
virtual bool draw(const SRenderData& data) override;
|
||||
virtual std::string type() const override; // Added for layered rendering
|
||||
|
||||
void reset();
|
||||
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
void reset();
|
||||
void renderUpdate();
|
||||
void onTimerUpdate();
|
||||
void plantTimer();
|
||||
|
||||
private:
|
||||
WP<CLabel> m_self;
|
||||
WP<CLabel> m_self;
|
||||
|
||||
std::string getUniqueResourceId();
|
||||
std::string getUniqueResourceId();
|
||||
|
||||
std::string labelPreFormat;
|
||||
IWidget::SFormatResult label;
|
||||
std::string labelPreFormat;
|
||||
IWidget::SFormatResult label;
|
||||
|
||||
Vector2D viewport;
|
||||
Vector2D pos;
|
||||
Vector2D configPos;
|
||||
double angle;
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID; // if dynamic label
|
||||
std::string halign, valign;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
|
||||
std::string outputStringPort;
|
||||
Vector2D viewport;
|
||||
Vector2D pos;
|
||||
Vector2D configPos;
|
||||
double angle;
|
||||
std::string resourceID;
|
||||
std::string pendingResourceID; // if dynamic label
|
||||
std::string halign, valign;
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
std::string outputStringPort;
|
||||
|
||||
CAsyncResourceGatherer::SPreloadRequest request;
|
||||
std::shared_ptr<CTimer> labelTimer = nullptr;
|
||||
|
||||
std::shared_ptr<CTimer> labelTimer = nullptr;
|
||||
|
||||
CShadowable shadow;
|
||||
bool updateShadow = true;
|
||||
};
|
||||
CShadowable shadow;
|
||||
bool updateShadow = true;
|
||||
};
|
|
@ -23,6 +23,10 @@ void CPasswordInputField::registerSelf(const SP<CPasswordInputField>& self) {
|
|||
m_self = self;
|
||||
}
|
||||
|
||||
std::string CPasswordInputField::type() const {
|
||||
return "input-field";
|
||||
}
|
||||
|
||||
void CPasswordInputField::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
reset();
|
||||
|
||||
|
@ -472,4 +476,4 @@ void CPasswordInputField::updateColors() {
|
|||
*colorState.inner = innerTarget;
|
||||
|
||||
colorState.font = fontTarget;
|
||||
}
|
||||
}
|
|
@ -19,105 +19,100 @@ class CPasswordInputField : public IWidget {
|
|||
CPasswordInputField() = default;
|
||||
virtual ~CPasswordInputField();
|
||||
|
||||
void registerSelf(const SP<CPasswordInputField>& self);
|
||||
void registerSelf(const SP<CPasswordInputField>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput) override;
|
||||
virtual bool draw(const SRenderData& data) override;
|
||||
virtual std::string type() const override; // Added for layered rendering
|
||||
|
||||
void reset();
|
||||
void onFadeOutTimer();
|
||||
void reset();
|
||||
void onFadeOutTimer();
|
||||
|
||||
private:
|
||||
WP<CPasswordInputField> m_self;
|
||||
|
||||
void updateDots();
|
||||
void updateFade();
|
||||
void updatePlaceholder();
|
||||
void updateWidth();
|
||||
void updateHiddenInputState();
|
||||
void updateInputState();
|
||||
void updateColors();
|
||||
void updateDots();
|
||||
void updateFade();
|
||||
void updatePlaceholder();
|
||||
void updateWidth();
|
||||
void updateHiddenInputState();
|
||||
void updateInputState();
|
||||
void updateColors();
|
||||
|
||||
bool firstRender = true;
|
||||
bool redrawShadow = false;
|
||||
bool checkWaiting = false;
|
||||
bool displayFail = false;
|
||||
bool firstRender = true;
|
||||
bool redrawShadow = false;
|
||||
bool checkWaiting = false;
|
||||
bool displayFail = false;
|
||||
|
||||
size_t passwordLength = 0;
|
||||
size_t passwordLength = 0;
|
||||
|
||||
PHLANIMVAR<Vector2D> size;
|
||||
Vector2D pos;
|
||||
Vector2D viewport;
|
||||
Vector2D configPos;
|
||||
Vector2D configSize;
|
||||
PHLANIMVAR<Vector2D> size;
|
||||
Vector2D pos;
|
||||
Vector2D viewport;
|
||||
Vector2D configPos;
|
||||
Vector2D configSize;
|
||||
|
||||
std::string halign, valign, configFailText, outputStringPort, configPlaceholderText, fontFamily;
|
||||
uint64_t configFailTimeoutMs = 2000;
|
||||
std::string halign, valign, configFailText, outputStringPort, configPlaceholderText, fontFamily;
|
||||
uint64_t configFailTimeoutMs = 2000;
|
||||
|
||||
int outThick, rounding;
|
||||
int outThick, rounding;
|
||||
|
||||
struct {
|
||||
PHLANIMVAR<float> currentAmount;
|
||||
bool center = false;
|
||||
float size = 0;
|
||||
float spacing = 0;
|
||||
int rounding = 0;
|
||||
std::string textFormat = "";
|
||||
std::string textResourceID;
|
||||
SPreloadedAsset* textAsset = nullptr;
|
||||
bool center = false;
|
||||
float size = 0;
|
||||
float spacing = 0;
|
||||
int rounding = 0;
|
||||
std::string textFormat = "";
|
||||
std::string textResourceID;
|
||||
SPreloadedAsset* textAsset = nullptr;
|
||||
} dots;
|
||||
|
||||
struct {
|
||||
PHLANIMVAR<float> a;
|
||||
bool appearing = true;
|
||||
PHLANIMVAR<float> a;
|
||||
bool appearing = true;
|
||||
std::shared_ptr<CTimer> fadeOutTimer = nullptr;
|
||||
bool allowFadeOut = false;
|
||||
bool allowFadeOut = false;
|
||||
} fade;
|
||||
|
||||
struct {
|
||||
std::string resourceID = "";
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
|
||||
std::string currentText = "";
|
||||
size_t failedAttempts = 0;
|
||||
|
||||
std::string resourceID = "";
|
||||
SPreloadedAsset* asset = nullptr;
|
||||
std::string currentText = "";
|
||||
size_t failedAttempts = 0;
|
||||
std::vector<std::string> registeredResourceIDs;
|
||||
} placeholder;
|
||||
|
||||
struct {
|
||||
CHyprColor lastColor;
|
||||
int lastQuadrant = 0;
|
||||
int lastPasswordLength = 0;
|
||||
bool enabled = false;
|
||||
int lastQuadrant = 0;
|
||||
int lastPasswordLength = 0;
|
||||
bool enabled = false;
|
||||
} hiddenInputState;
|
||||
|
||||
struct {
|
||||
CGradientValueData* outer = nullptr;
|
||||
CHyprColor inner;
|
||||
CHyprColor font;
|
||||
CGradientValueData* fail = nullptr;
|
||||
CHyprColor inner;
|
||||
CHyprColor font;
|
||||
CGradientValueData* fail = nullptr;
|
||||
CGradientValueData* check = nullptr;
|
||||
CGradientValueData* caps = nullptr;
|
||||
CGradientValueData* num = nullptr;
|
||||
CGradientValueData* both = nullptr;
|
||||
|
||||
CHyprColor hiddenBase;
|
||||
|
||||
int transitionMs = 0;
|
||||
bool invertNum = false;
|
||||
bool swapFont = false;
|
||||
CGradientValueData* caps = nullptr;
|
||||
CGradientValueData* num = nullptr;
|
||||
CGradientValueData* both = nullptr;
|
||||
CHyprColor hiddenBase;
|
||||
int transitionMs = 0;
|
||||
bool invertNum = false;
|
||||
bool swapFont = false;
|
||||
} colorConfig;
|
||||
|
||||
struct {
|
||||
PHLANIMVAR<CGradientValueData> outer;
|
||||
PHLANIMVAR<CHyprColor> inner;
|
||||
// Font color is only chaned, when `swap_font_color` is set to true and no border is present.
|
||||
// It is not animated, because that does not look good and we would need to rerender the text for each frame.
|
||||
PHLANIMVAR<CHyprColor> inner;
|
||||
CHyprColor font;
|
||||
} colorState;
|
||||
|
||||
bool fadeOnEmpty;
|
||||
uint64_t fadeTimeoutMs;
|
||||
bool fadeOnEmpty;
|
||||
uint64_t fadeTimeoutMs;
|
||||
|
||||
CShadowable shadow;
|
||||
};
|
||||
};
|
|
@ -1,102 +1,235 @@
|
|||
#include "Shape.hpp"
|
||||
#include "../Renderer.hpp"
|
||||
#include "../../config/ConfigDataValues.hpp"
|
||||
#include <cmath>
|
||||
#include "../../helpers/Log.hpp"
|
||||
#include <hyprlang.hpp>
|
||||
#include <GLES3/gl32.h>
|
||||
#include <cmath>
|
||||
#include <optional> // Added for SBlurParams::std::optional<CHyprColor>
|
||||
|
||||
void CShape::registerSelf(const SP<CShape>& self) {
|
||||
m_self = self;
|
||||
}
|
||||
|
||||
std::string CShape::type() const {
|
||||
return "shape";
|
||||
}
|
||||
|
||||
void CShape::configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput) {
|
||||
viewport = pOutput->getViewport();
|
||||
|
||||
shadow.configure(m_self.lock(), props, viewport);
|
||||
|
||||
try {
|
||||
size = CLayoutValueData::fromAnyPv(props.at("size"))->getAbsolute(viewport);
|
||||
rounding = std::any_cast<Hyprlang::INT>(props.at("rounding"));
|
||||
border = std::any_cast<Hyprlang::INT>(props.at("border_size"));
|
||||
color = std::any_cast<Hyprlang::INT>(props.at("color"));
|
||||
borderGrad = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
pos = CLayoutValueData::fromAnyPv(props.at("position"))->getAbsolute(viewport);
|
||||
halign = std::any_cast<Hyprlang::STRING>(props.at("halign"));
|
||||
valign = std::any_cast<Hyprlang::STRING>(props.at("valign"));
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(props.at("rotate"));
|
||||
xray = std::any_cast<Hyprlang::INT>(props.at("xray"));
|
||||
} catch (const std::bad_any_cast& e) {
|
||||
RASSERT(false, "Failed to construct CShape: {}", e.what()); //
|
||||
} catch (const std::out_of_range& e) {
|
||||
RASSERT(false, "Missing property for CShape: {}", e.what()); //
|
||||
}
|
||||
// Parse position
|
||||
pos = {0, 0};
|
||||
if (props.contains("position")) {
|
||||
auto val = props.at("position");
|
||||
if (val.type() == typeid(Hyprlang::VEC2)) {
|
||||
auto vec = std::any_cast<Hyprlang::VEC2>(val);
|
||||
pos = {static_cast<double>(vec.x), static_cast<double>(vec.y)};
|
||||
} else {
|
||||
Debug::log(WARN, "Shape position has unexpected type, defaulting to (0, 0)");
|
||||
}
|
||||
}
|
||||
|
||||
angle = angle * M_PI / 180.0;
|
||||
// Parse size
|
||||
size = {100, 100};
|
||||
if (props.contains("size")) {
|
||||
auto val = props.at("size");
|
||||
if (val.type() == typeid(Hyprlang::VEC2)) {
|
||||
auto vec = std::any_cast<Hyprlang::VEC2>(val);
|
||||
size = {static_cast<double>(vec.x), static_cast<double>(vec.y)};
|
||||
} else {
|
||||
Debug::log(WARN, "Shape size has unexpected type, defaulting to 100x100");
|
||||
}
|
||||
}
|
||||
|
||||
const Vector2D VBORDER = {border, border};
|
||||
const Vector2D REALSIZE = size + VBORDER * 2.0;
|
||||
const Vector2D OFFSET = angle == 0 ? Vector2D{0.0, 0.0} : Vector2D{1.0, 1.0};
|
||||
// Parse color
|
||||
color = CHyprColor(1.0, 1.0, 1.0, 0.5); // Semi-transparent white default
|
||||
if (props.contains("color")) {
|
||||
auto colorVal = props.at("color");
|
||||
if (colorVal.type() == typeid(Hyprlang::STRING)) {
|
||||
std::string colorStr = std::any_cast<Hyprlang::STRING>(colorVal);
|
||||
if (colorStr.starts_with("0x") || colorStr.starts_with("#"))
|
||||
colorStr = colorStr.substr(2);
|
||||
uint64_t colorValue = std::stoull(colorStr, nullptr, 16);
|
||||
color = CHyprColor(colorValue);
|
||||
} else if (colorVal.type() == typeid(Hyprlang::INT)) {
|
||||
uint64_t colorValue = std::any_cast<Hyprlang::INT>(colorVal);
|
||||
color = CHyprColor(colorValue);
|
||||
} else {
|
||||
Debug::log(WARN, "Shape color has unexpected type, defaulting to semi-transparent white");
|
||||
}
|
||||
}
|
||||
|
||||
pos = posFromHVAlign(viewport, xray ? size : REALSIZE + OFFSET * 2.0, pos, halign, valign, xray ? 0 : angle);
|
||||
// Parse shape type
|
||||
shapeType = "rectangle";
|
||||
if (props.contains("shape")) {
|
||||
auto val = props.at("shape");
|
||||
if (val.type() == typeid(Hyprlang::STRING)) {
|
||||
shapeType = std::any_cast<Hyprlang::STRING>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "Shape type has unexpected type, defaulting to rectangle");
|
||||
}
|
||||
}
|
||||
|
||||
if (xray) {
|
||||
shapeBox = {pos, size};
|
||||
borderBox = {pos - VBORDER, REALSIZE};
|
||||
} else {
|
||||
shapeBox = {OFFSET + VBORDER, size};
|
||||
borderBox = {OFFSET, REALSIZE};
|
||||
// Parse blur
|
||||
blurEnabled = false;
|
||||
blurParams = {.size = 0, .passes = 0}; // Initialize local blurParams struct
|
||||
if (props.contains("blur")) {
|
||||
auto val = props.at("blur");
|
||||
if (val.type() == typeid(Hyprlang::INT) && std::any_cast<Hyprlang::INT>(val) > 0) {
|
||||
blurEnabled = true;
|
||||
blurParams.size = std::any_cast<Hyprlang::INT>(val);
|
||||
blurParams.passes = 3; // Default passes
|
||||
} else if (val.type() == typeid(Hyprlang::FLOAT) && std::any_cast<Hyprlang::FLOAT>(val) > 0) {
|
||||
blurEnabled = true;
|
||||
blurParams.size = static_cast<int>(std::any_cast<Hyprlang::FLOAT>(val));
|
||||
blurParams.passes = 3;
|
||||
} else {
|
||||
Debug::log(WARN, "Shape blur has unexpected type or value, disabling blur");
|
||||
}
|
||||
}
|
||||
|
||||
// Parse zindex
|
||||
zindex = 10; // Default: above background, below input-field
|
||||
if (props.contains("zindex")) {
|
||||
auto val = props.at("zindex");
|
||||
if (val.type() == typeid(Hyprlang::INT)) {
|
||||
zindex = std::any_cast<Hyprlang::INT>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "Shape zindex has unexpected type, defaulting to 10");
|
||||
}
|
||||
}
|
||||
|
||||
// Parse rotation (angle in degrees)
|
||||
angle = 0.0;
|
||||
if (props.contains("rotate")) {
|
||||
auto val = props.at("rotate");
|
||||
if (val.type() == typeid(Hyprlang::FLOAT)) {
|
||||
angle = std::any_cast<Hyprlang::FLOAT>(val);
|
||||
} else if (val.type() == typeid(Hyprlang::INT)) {
|
||||
angle = static_cast<float>(std::any_cast<Hyprlang::INT>(val));
|
||||
} else {
|
||||
Debug::log(WARN, "Shape rotate has unexpected type, defaulting to 0");
|
||||
}
|
||||
}
|
||||
angle = angle * M_PI / 180.0; // Convert to radians
|
||||
|
||||
// Parse border (optional)
|
||||
border = 0;
|
||||
if (props.contains("border_size")) {
|
||||
auto val = props.at("border_size");
|
||||
if (val.type() == typeid(Hyprlang::INT)) {
|
||||
border = std::any_cast<Hyprlang::INT>(val);
|
||||
} else {
|
||||
Debug::log(WARN, "Shape border_size has unexpected type, defaulting to 0");
|
||||
}
|
||||
}
|
||||
|
||||
// Parse border gradient (optional)
|
||||
borderGrad = CGradientValueData();
|
||||
if (props.contains("border_color")) {
|
||||
try {
|
||||
borderGrad = *CGradientValueData::fromAnyPv(props.at("border_color"));
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(WARN, "Failed to parse border_color, defaulting to empty gradient: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
// Parse halign and valign
|
||||
halign = "left";
|
||||
if (props.contains("halign")) {
|
||||
auto val = props.at("halign");
|
||||
if (val.type() == typeid(Hyprlang::STRING)) {
|
||||
halign = std::any_cast<Hyprlang::STRING>(val);
|
||||
}
|
||||
}
|
||||
valign = "top";
|
||||
if (props.contains("valign")) {
|
||||
auto val = props.at("valign");
|
||||
if (val.type() == typeid(Hyprlang::STRING)) {
|
||||
valign = std::any_cast<Hyprlang::STRING>(val);
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust position based on halign/valign
|
||||
Vector2D realSize = size + Vector2D{border * 2.0, border * 2.0};
|
||||
pos = posFromHVAlign(viewport, realSize, pos, halign, valign, angle);
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "CShape::configure failed: {}", e.what());
|
||||
// Set safe defaults
|
||||
pos = {0, 0};
|
||||
size = {100, 100};
|
||||
color = CHyprColor(1.0, 1.0, 1.0, 0.5);
|
||||
shapeType = "rectangle";
|
||||
zindex = 10;
|
||||
angle = 0.0;
|
||||
border = 0;
|
||||
blurEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool CShape::draw(const SRenderData& data) {
|
||||
try {
|
||||
CBox box = {pos.x, pos.y, size.x, size.y};
|
||||
box.round();
|
||||
box.rot = angle;
|
||||
|
||||
if (firstRender) {
|
||||
firstRender = false;
|
||||
shadow.markShadowDirty();
|
||||
}
|
||||
if (blurEnabled) {
|
||||
if (!shapeFB.isAllocated()) {
|
||||
shapeFB.alloc((int)(size.x + border * 2), (int)(size.y + border * 2), true);
|
||||
}
|
||||
|
||||
shadow.draw(data);
|
||||
shapeFB.bind();
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
const auto MINHALFBORDER = std::min(borderBox.w, borderBox.h) / 2.0;
|
||||
// Draw shape (rectangle for now)
|
||||
if (shapeType == "rectangle") {
|
||||
CBox shapeBox = {border, border, size.x, size.y};
|
||||
g_pRenderer->renderRect(shapeBox, color, 0);
|
||||
if (border > 0 && !borderGrad.m_vColorsOkLabA.empty()) {
|
||||
CBox borderBox = {0, 0, size.x + border * 2, size.y + border * 2};
|
||||
g_pRenderer->renderBorder(borderBox, borderGrad, border, 0, data.opacity);
|
||||
}
|
||||
} else {
|
||||
Debug::log(WARN, "Shape type {} not implemented, rendering rectangle", shapeType);
|
||||
g_pRenderer->renderRect(box, color, 0);
|
||||
}
|
||||
|
||||
if (xray) {
|
||||
if (border > 0) {
|
||||
const int PIROUND = std::min(MINHALFBORDER, std::round(border * M_PI));
|
||||
g_pRenderer->renderBorder(borderBox, borderGrad, border, rounding == -1 ? PIROUND : std::clamp(rounding, 0, PIROUND), data.opacity);
|
||||
// Apply blur
|
||||
CRenderer::SBlurParams rendererBlurParams = {
|
||||
.size = blurParams.size,
|
||||
.passes = blurParams.passes,
|
||||
// Default values for other fields
|
||||
};
|
||||
g_pRenderer->blurFB(shapeFB, rendererBlurParams);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
|
||||
// Render blurred texture
|
||||
CBox texBox = {pos.x - border, pos.y - border, size.x + border * 2, size.y + border * 2};
|
||||
texBox.round();
|
||||
texBox.rot = angle;
|
||||
g_pRenderer->renderTexture(texBox, shapeFB.m_cTex, data.opacity, 0, HYPRUTILS_TRANSFORM_FLIPPED_180);
|
||||
} else {
|
||||
// Draw without blur
|
||||
if (shapeType == "rectangle") {
|
||||
g_pRenderer->renderRect(box, color, 0);
|
||||
if (border > 0 && !borderGrad.m_vColorsOkLabA.empty()) {
|
||||
CBox borderBox = {pos.x - border, pos.y - border, size.x + border * 2, size.y + border * 2};
|
||||
borderBox.round();
|
||||
borderBox.rot = angle;
|
||||
g_pRenderer->renderBorder(borderBox, borderGrad, border, 0, data.opacity);
|
||||
}
|
||||
} else {
|
||||
Debug::log(WARN, "Shape type {} not implemented, rendering rectangle", shapeType);
|
||||
g_pRenderer->renderRect(box, color, 0);
|
||||
}
|
||||
}
|
||||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(shapeBox.x, shapeBox.y, shapeBox.width, shapeBox.height);
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
return data.opacity < 1.0;
|
||||
} catch (const std::exception& e) {
|
||||
Debug::log(ERR, "CShape::draw failed: {}", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!shapeFB.isAllocated()) {
|
||||
const int ROUND = roundingForBox(shapeBox, rounding);
|
||||
const int BORDERROUND = roundingForBorderBox(borderBox, rounding, border);
|
||||
Debug::log(LOG, "round: {}, borderround: {}", ROUND, BORDERROUND);
|
||||
|
||||
shapeFB.alloc(borderBox.width + (borderBox.x * 2.0), borderBox.height + (borderBox.y * 2.0), true);
|
||||
g_pRenderer->pushFb(shapeFB.m_iFb);
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if (border > 0)
|
||||
g_pRenderer->renderBorder(borderBox, borderGrad, border, BORDERROUND, 1.0);
|
||||
|
||||
g_pRenderer->renderRect(shapeBox, color, ROUND);
|
||||
g_pRenderer->popFb();
|
||||
}
|
||||
|
||||
CTexture* tex = &shapeFB.m_cTex;
|
||||
CBox texbox = {pos, tex->m_vSize};
|
||||
|
||||
texbox.round();
|
||||
texbox.rot = angle;
|
||||
|
||||
g_pRenderer->renderTexture(texbox, *tex, data.opacity, 0, HYPRUTILS_TRANSFORM_FLIPPED_180);
|
||||
|
||||
return data.opacity < 1.0;
|
||||
}
|
||||
}
|
|
@ -11,34 +11,37 @@
|
|||
|
||||
class CShape : public IWidget {
|
||||
public:
|
||||
CShape() = default;
|
||||
CShape() = default;
|
||||
virtual ~CShape() = default;
|
||||
|
||||
void registerSelf(const SP<CShape>& self);
|
||||
void registerSelf(const SP<CShape>& self);
|
||||
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput);
|
||||
virtual bool draw(const SRenderData& data);
|
||||
virtual void configure(const std::unordered_map<std::string, std::any>& prop, const SP<COutput>& pOutput) override;
|
||||
virtual bool draw(const SRenderData& data) override;
|
||||
virtual std::string type() const override; // Added for layered rendering
|
||||
|
||||
private:
|
||||
WP<CShape> m_self;
|
||||
WP<CShape> m_self;
|
||||
|
||||
CFramebuffer shapeFB;
|
||||
CFramebuffer shapeFB;
|
||||
|
||||
int rounding;
|
||||
double border;
|
||||
double angle;
|
||||
CHyprColor color;
|
||||
std::string shapeType; // e.g., "rectangle"
|
||||
bool blurEnabled = false;
|
||||
struct {
|
||||
int size = 0;
|
||||
int passes = 0;
|
||||
} blurParams;
|
||||
int zindex = 10; // Default: above background, below input-field
|
||||
|
||||
int rounding;
|
||||
double border;
|
||||
double angle;
|
||||
CHyprColor color;
|
||||
CGradientValueData borderGrad;
|
||||
Vector2D size;
|
||||
Vector2D pos;
|
||||
CBox shapeBox;
|
||||
CBox borderBox;
|
||||
bool xray;
|
||||
Vector2D size;
|
||||
Vector2D pos;
|
||||
|
||||
std::string halign, valign;
|
||||
|
||||
bool firstRender = true;
|
||||
|
||||
Vector2D viewport;
|
||||
CShadowable shadow;
|
||||
};
|
||||
std::string halign, valign;
|
||||
Vector2D viewport;
|
||||
CShadowable shadow;
|
||||
};
|
Loading…
Reference in a new issue