Skip to content

Commit

Permalink
add affectStrut option
Browse files Browse the repository at this point in the history
  • Loading branch information
KZDKM committed Apr 18, 2024
1 parent 9d6b96f commit 26b9b64
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Refer to the [Hyprland wiki](https://wiki.hyprland.org/Nix/Hyprland-on-Home-Mana
- `plugin:overview:overrideGaps` whether if overview should override the layout gaps in the current workspace using the following values
- `plugin:overview:gapsIn`
- `plugin:overview:gapsOut`
- `plugin:overview:affectStrut` whether the panel should push window aside, disabling this option also disables `overrideGaps`

### Animation
- The panel uses the `windows` curve for a slide-in animation
Expand Down
1 change: 1 addition & 0 deletions src/Globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Config {
extern bool hideOverlayLayers;
extern bool drawActiveWorkspace;
extern bool hideRealLayers;
extern bool affectStrut;

extern bool overrideGaps;
extern int gapsIn;
Expand Down
30 changes: 15 additions & 15 deletions src/Input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@ bool CHyprspaceWidget::buttonEvent(bool pressed) {
lastPressedTime = std::chrono::high_resolution_clock::now();
else
if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - lastPressedTime).count() < 200)
couldExit = true;

if (Config::autoDrag) {
// when overview is active, always drag windows on mouse click
if (g_pInputManager->currentlyDraggedWindow) {
g_pLayoutManager->getCurrentLayout()->onEndDragWindow();
g_pInputManager->currentlyDraggedWindow = nullptr;
g_pInputManager->dragMode = MBIND_INVALID;
}
std::string keybind = (pressed ? "1" : "0") + std::string("movewindow");
(*(tMouseKeybind)pMouseKeybind)(keybind);
}
Return = false;
couldExit = true;

int targetWorkspaceID = SPECIAL_WORKSPACE_START - 1;

Expand All @@ -41,9 +29,21 @@ bool CHyprspaceWidget::buttonEvent(bool pressed) {
auto targetWorkspace = g_pCompositor->getWorkspaceByID(targetWorkspaceID);

// create new workspace
if (!targetWorkspace && targetWorkspaceID >= SPECIAL_WORKSPACE_START) {
if (!targetWorkspace.get() && targetWorkspaceID >= SPECIAL_WORKSPACE_START) {
targetWorkspace = g_pCompositor->createNewWorkspace(targetWorkspaceID, getOwner()->ID);
}

if (Config::autoDrag && (!targetWorkspace.get() || !pressed)) {
// when overview is active, always drag windows on mouse click
if (g_pInputManager->currentlyDraggedWindow) {
g_pLayoutManager->getCurrentLayout()->onEndDragWindow();
g_pInputManager->currentlyDraggedWindow = nullptr;
g_pInputManager->dragMode = MBIND_INVALID;
}
std::string keybind = (pressed ? "1" : "0") + std::string("movewindow");
(*(tMouseKeybind)pMouseKeybind)(keybind);
}
Return = false;

// release window on workspace to drop it in
if (targetWindow && targetWorkspace.get() && !pressed) {
Expand All @@ -70,7 +70,7 @@ bool CHyprspaceWidget::buttonEvent(bool pressed) {
if (Config::exitOnSwitch && active) hide();
}
// click elsewhere to exit overview
else if (Config::exitOnClick && !targetWorkspace.get() && active && couldExit && !pressed) hide();
else if (Config::exitOnClick && !targetWorkspace.get() && active && couldExit && !pressed) hide();

return Return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

// FIXME: preserve original workspace rules
void CHyprspaceWidget::updateLayout() {

if (!Config::affectStrut) return;

const auto currentHeight = Config::panelHeight + Config::reservedArea;
const auto pMonitor = getOwner();
// reset reserved areas
Expand Down
2 changes: 1 addition & 1 deletion src/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void CHyprspaceWidget::draw() {
}
}

if (owner->activeWorkspace == ws) {
if (owner->activeWorkspace == ws && Config::affectStrut) {
CBox miniPanelBox = {curWorkspaceRectOffsetX, curWorkspaceRectOffsetY, widgetBox.w * monitorSizeScaleFactor, widgetBox.h * monitorSizeScaleFactor};
if (Config::onBottom) miniPanelBox = {curWorkspaceRectOffsetX, curWorkspaceRectOffsetY + workspaceBoxH - widgetBox.h * monitorSizeScaleFactor, widgetBox.w * monitorSizeScaleFactor, widgetBox.h * monitorSizeScaleFactor};
g_pHyprOpenGL->renderRectWithBlur(&miniPanelBox, CColor(0, 0, 0, 0), 0, 1.f, false);
Expand Down
27 changes: 21 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bool Config::hideTopLayers = false;
bool Config::hideOverlayLayers = false;
bool Config::drawActiveWorkspace = true;
bool Config::hideRealLayers = true;
bool Config::affectStrut = true;

bool Config::overrideGaps = true;
int Config::gapsIn = 20;
Expand Down Expand Up @@ -98,10 +99,10 @@ void onRender(void* thisptr, SCallbackInfo& info, std::any args) {
const auto widget = getWidgetForMonitor(g_pHyprOpenGL->m_RenderData.pMonitor);
if (widget.get())
if (widget->getOwner()) {
widget->draw();
//widget->draw();
if (g_pInputManager->currentlyDraggedWindow && widget->isActive()) {
g_oAlpha = g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.goal();
g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.setValueAndWarp(Config::dragAlpha);
g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.setValueAndWarp(0); // HACK: hide dragged window for the actual pass
}
else g_oAlpha = -1;
}
Expand All @@ -110,10 +111,22 @@ void onRender(void* thisptr, SCallbackInfo& info, std::any args) {

}
else if (renderStage == eRenderStage::RENDER_POST_WINDOWS) {
if (g_oAlpha != -1 && g_pInputManager->currentlyDraggedWindow) {
g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.setValueAndWarp(g_oAlpha);
}
g_oAlpha = -1;

const auto widget = getWidgetForMonitor(g_pHyprOpenGL->m_RenderData.pMonitor);

if (widget.get())
if (widget->getOwner()) {
widget->draw();
if (g_oAlpha != -1 && g_pInputManager->currentlyDraggedWindow) {
g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.setValueAndWarp(Config::dragAlpha);
timespec time;
clock_gettime(CLOCK_MONOTONIC, &time);
(*(tRenderWindow)pRenderWindow)(g_pHyprRenderer.get(), g_pInputManager->currentlyDraggedWindow, widget->getOwner(), &time, true, RENDER_PASS_MAIN, false, false);
g_pInputManager->currentlyDraggedWindow->m_fActiveInactiveAlpha.setValueAndWarp(g_oAlpha);
}
g_oAlpha = -1;
}

}
}

Expand Down Expand Up @@ -305,6 +318,7 @@ void reloadConfig() {
Config::hideOverlayLayers = std::any_cast<Hyprlang::INT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:hideOverlayLayers")->getValue());
Config::drawActiveWorkspace = std::any_cast<Hyprlang::INT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:drawActiveWorkspace")->getValue());
Config::hideRealLayers = std::any_cast<Hyprlang::INT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:hideRealLayers")->getValue());
Config::affectStrut = std::any_cast<Hyprlang::INT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:affectStrut")->getValue());

Config::overrideGaps = std::any_cast<Hyprlang::INT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:overrideGaps")->getValue());
Config::gapsIn = std::any_cast<Hyprlang::INT>(HyprlandAPI::getConfigValue(pHandle, "plugin:overview:gapsIn")->getValue());
Expand Down Expand Up @@ -372,6 +386,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE inHandle) {
HyprlandAPI::addConfigValue(pHandle, "plugin:overview:hideOverlayLayers", Hyprlang::INT{0});
HyprlandAPI::addConfigValue(pHandle, "plugin:overview:drawActiveWorkspace", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(pHandle, "plugin:overview:hideRealLayers", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(pHandle, "plugin:overview:affectStrut", Hyprlang::INT{1});

HyprlandAPI::addConfigValue(pHandle, "plugin:overview:overrideGaps", Hyprlang::INT{1});
HyprlandAPI::addConfigValue(pHandle, "plugin:overview:gapsIn", Hyprlang::INT{20});
Expand Down

0 comments on commit 26b9b64

Please sign in to comment.