mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-22 21:35:58 +01:00
optimize out refreshing and stuff
This commit is contained in:
parent
380ee051c9
commit
1e16487db0
7 changed files with 75 additions and 26 deletions
|
@ -4,6 +4,10 @@ project(Hypr
|
||||||
DESCRIPTION "A Modern OOP C++ Window Manager"
|
DESCRIPTION "A Modern OOP C++ Window Manager"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(CMAKE_MESSAGE_LOG_LEVEL "STATUS")
|
||||||
|
|
||||||
|
message(STATUS "Building Hypr!")
|
||||||
|
|
||||||
add_compile_options(-std=c++17)
|
add_compile_options(-std=c++17)
|
||||||
add_compile_options(-Wall -Wextra)
|
add_compile_options(-Wall -Wextra)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
@ -15,6 +19,13 @@ file(GLOB_RECURSE SRCFILES "src/*.cpp")
|
||||||
|
|
||||||
add_executable(Hypr ${SRCFILES})
|
add_executable(Hypr ${SRCFILES})
|
||||||
|
|
||||||
|
IF(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||||
|
message(STATUS "Building Hypr in Debug with CMake!")
|
||||||
|
ELSE()
|
||||||
|
add_compile_options(-Ofast)
|
||||||
|
message(STATUS "Building Hypr in Release with CMake!")
|
||||||
|
ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||||
|
|
||||||
target_link_libraries(Hypr rt)
|
target_link_libraries(Hypr rt)
|
||||||
|
|
||||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||||
|
@ -35,3 +46,9 @@ target_link_libraries(Hypr
|
||||||
xcb-util
|
xcb-util
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
IF(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||||
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg -no-pie -fno-builtin")
|
||||||
|
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg -no-pie -fno-builtin")
|
||||||
|
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg -no-pie -fno-builtin")
|
||||||
|
ENDIF(CMAKE_BUILD_TYPE MATCHES DEBUG OR CMAKE_BUILD_TYPE MATCHES DEBUG)
|
|
@ -461,14 +461,14 @@ void ConfigManager::tick() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigManager::getInt(std::string_view v) {
|
int ConfigManager::getInt(std::string v) {
|
||||||
return configValues[v].intValue;
|
return configValues[v].intValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float ConfigManager::getFloat(std::string_view v) {
|
float ConfigManager::getFloat(std::string v) {
|
||||||
return configValues[v].floatValue;
|
return configValues[v].floatValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ConfigManager::getString(std::string_view v) {
|
std::string ConfigManager::getString(std::string v) {
|
||||||
return configValues[v].strValue;
|
return configValues[v].strValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "../utilities/Debug.hpp"
|
#include "../utilities/Debug.hpp"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
enum ELayouts {
|
enum ELayouts {
|
||||||
LAYOUT_DWINDLE = 0,
|
LAYOUT_DWINDLE = 0,
|
||||||
|
@ -15,7 +16,7 @@ struct SConfigValue {
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace ConfigManager {
|
namespace ConfigManager {
|
||||||
inline std::map<std::string_view, SConfigValue> configValues;
|
inline std::unordered_map<std::string, SConfigValue> configValues;
|
||||||
inline time_t lastModifyTime = 0;
|
inline time_t lastModifyTime = 0;
|
||||||
|
|
||||||
inline bool loadBar = false;
|
inline bool loadBar = false;
|
||||||
|
@ -32,7 +33,7 @@ namespace ConfigManager {
|
||||||
|
|
||||||
void applyKeybindsToX();
|
void applyKeybindsToX();
|
||||||
|
|
||||||
int getInt(std::string_view);
|
int getInt(std::string);
|
||||||
float getFloat(std::string_view);
|
float getFloat(std::string);
|
||||||
std::string getString(std::string_view);
|
std::string getString(std::string);
|
||||||
};
|
};
|
|
@ -27,6 +27,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "./helpers/Vector.hpp"
|
#include "./helpers/Vector.hpp"
|
||||||
#include "./utilities/Debug.hpp"
|
#include "./utilities/Debug.hpp"
|
||||||
|
@ -41,8 +42,8 @@
|
||||||
private: \
|
private: \
|
||||||
type m_##prefix##var; \
|
type m_##prefix##var; \
|
||||||
public: \
|
public: \
|
||||||
type get##var() { return this->m_##prefix##var; } \
|
inline type get##var() { return m_##prefix##var; } \
|
||||||
void set##var(type value) { this->m_##prefix##var = value; }
|
void set##var(type value) { m_##prefix##var = value; }
|
||||||
|
|
||||||
|
|
||||||
#define EVENT(name) \
|
#define EVENT(name) \
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "windowManager.hpp"
|
#include "windowManager.hpp"
|
||||||
|
|
||||||
CWindow::CWindow() { this->setDock(false); this->setUnderFullscreen(false); this->setIsSleeping(true); this->setFirstAnimFrame(true); this->setIsAnimated(false); this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); }
|
CWindow::CWindow() { this->setLastUpdatePosition(Vector2D(0,0)); this->setLastUpdateSize(Vector2D(0,0)); this->setDock(false); this->setUnderFullscreen(false); this->setIsSleeping(true); this->setFirstAnimFrame(true); this->setIsAnimated(false); this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); }
|
||||||
CWindow::~CWindow() { }
|
CWindow::~CWindow() { }
|
||||||
|
|
||||||
void CWindow::generateNodeID() {
|
void CWindow::generateNodeID() {
|
||||||
|
|
|
@ -49,6 +49,8 @@ public:
|
||||||
EXPOSED_MEMBER(Position, Vector2D, vec);
|
EXPOSED_MEMBER(Position, Vector2D, vec);
|
||||||
EXPOSED_MEMBER(RealSize, Vector2D, vec);
|
EXPOSED_MEMBER(RealSize, Vector2D, vec);
|
||||||
EXPOSED_MEMBER(RealPosition, Vector2D, vec);
|
EXPOSED_MEMBER(RealPosition, Vector2D, vec);
|
||||||
|
EXPOSED_MEMBER(LastUpdateSize, Vector2D, vec);
|
||||||
|
EXPOSED_MEMBER(LastUpdatePosition, Vector2D, vec);
|
||||||
EXPOSED_MEMBER(IsFloating, bool, b);
|
EXPOSED_MEMBER(IsFloating, bool, b);
|
||||||
EXPOSED_MEMBER(Drawable, int64_t, i); // int64_t because it's my internal ID system too.
|
EXPOSED_MEMBER(Drawable, int64_t, i); // int64_t because it's my internal ID system too.
|
||||||
|
|
||||||
|
|
|
@ -331,6 +331,7 @@ void CWindowManager::cleanupUnusedWorkspaces() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowManager::refreshDirtyWindows() {
|
void CWindowManager::refreshDirtyWindows() {
|
||||||
|
const auto START = std::chrono::high_resolution_clock::now();
|
||||||
for(auto& window : windows) {
|
for(auto& window : windows) {
|
||||||
if (window.getDirty()) {
|
if (window.getDirty()) {
|
||||||
window.setDirty(false);
|
window.setDirty(false);
|
||||||
|
@ -351,12 +352,18 @@ void CWindowManager::refreshDirtyWindows() {
|
||||||
// Move it to hades
|
// Move it to hades
|
||||||
Values[0] = (int)1500000; // hmu when monitors actually have that many pixels
|
Values[0] = (int)1500000; // hmu when monitors actually have that many pixels
|
||||||
Values[1] = (int)1500000; // and we are still using xorg =)
|
Values[1] = (int)1500000; // and we are still using xorg =)
|
||||||
|
if (VECTORDELTANONZERO(window.getLastUpdatePosition(), Vector2D(Values[0], Values[1]))) {
|
||||||
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values);
|
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values);
|
||||||
|
window.setLastUpdatePosition(Vector2D(Values[0], Values[1]));
|
||||||
|
}
|
||||||
|
|
||||||
// Set the size JIC.
|
// Set the size JIC.
|
||||||
Values[0] = (int)window.getEffectiveSize().x;
|
Values[0] = (int)window.getEffectiveSize().x;
|
||||||
Values[1] = (int)window.getEffectiveSize().y;
|
Values[1] = (int)window.getEffectiveSize().y;
|
||||||
|
if (VECTORDELTANONZERO(window.getLastUpdateSize(), Vector2D(Values[0], Values[1]))) {
|
||||||
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
|
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
|
||||||
|
window.setLastUpdateSize(Vector2D(Values[0], Values[1]));
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -370,11 +377,17 @@ void CWindowManager::refreshDirtyWindows() {
|
||||||
|
|
||||||
Values[0] = (int)MONITOR->vecSize.x;
|
Values[0] = (int)MONITOR->vecSize.x;
|
||||||
Values[1] = (int)MONITOR->vecSize.y;
|
Values[1] = (int)MONITOR->vecSize.y;
|
||||||
|
if (VECTORDELTANONZERO(window.getLastUpdateSize(), Vector2D(Values[0], Values[1]))) {
|
||||||
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
|
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
|
||||||
|
window.setLastUpdateSize(Vector2D(Values[0], Values[1]));
|
||||||
|
}
|
||||||
|
|
||||||
Values[0] = (int)MONITOR->vecPosition.x;
|
Values[0] = (int)MONITOR->vecPosition.x;
|
||||||
Values[1] = (int)MONITOR->vecPosition.y;
|
Values[1] = (int)MONITOR->vecPosition.y;
|
||||||
|
if (VECTORDELTANONZERO(window.getLastUpdatePosition(), Vector2D(Values[0], Values[1]))) {
|
||||||
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values);
|
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values);
|
||||||
|
window.setLastUpdatePosition(Vector2D(Values[0], Values[1]));
|
||||||
|
}
|
||||||
|
|
||||||
// Apply rounded corners, does all the checks inside
|
// Apply rounded corners, does all the checks inside
|
||||||
applyShapeToWindow(&window);
|
applyShapeToWindow(&window);
|
||||||
|
@ -386,7 +399,10 @@ void CWindowManager::refreshDirtyWindows() {
|
||||||
// I have added the bordersize vec2d before in the setEffectiveSizePosUsingConfig function.
|
// I have added the bordersize vec2d before in the setEffectiveSizePosUsingConfig function.
|
||||||
Values[0] = (int)window.getRealPosition().x - ConfigManager::getInt("border_size");
|
Values[0] = (int)window.getRealPosition().x - ConfigManager::getInt("border_size");
|
||||||
Values[1] = (int)window.getRealPosition().y - ConfigManager::getInt("border_size");
|
Values[1] = (int)window.getRealPosition().y - ConfigManager::getInt("border_size");
|
||||||
|
if (VECTORDELTANONZERO(window.getLastUpdatePosition(), Vector2D(Values[0], Values[1]))) {
|
||||||
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values);
|
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, Values);
|
||||||
|
window.setLastUpdatePosition(Vector2D(Values[0], Values[1]));
|
||||||
|
}
|
||||||
|
|
||||||
Values[0] = (int)ConfigManager::getInt("border_size");
|
Values[0] = (int)ConfigManager::getInt("border_size");
|
||||||
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_BORDER_WIDTH, Values);
|
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_BORDER_WIDTH, Values);
|
||||||
|
@ -400,7 +416,10 @@ void CWindowManager::refreshDirtyWindows() {
|
||||||
if (!window.getIsAnimated() || ConfigManager::getInt("anim:cheap") == 0) {
|
if (!window.getIsAnimated() || ConfigManager::getInt("anim:cheap") == 0) {
|
||||||
Values[0] = (int)window.getRealSize().x;
|
Values[0] = (int)window.getRealSize().x;
|
||||||
Values[1] = (int)window.getRealSize().y;
|
Values[1] = (int)window.getRealSize().y;
|
||||||
|
if (VECTORDELTANONZERO(window.getLastUpdateSize(), Vector2D(Values[0], Values[1]))) {
|
||||||
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
|
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
|
||||||
|
window.setLastUpdateSize(Vector2D(Values[0], Values[1]));
|
||||||
|
}
|
||||||
window.setFirstAnimFrame(true);
|
window.setFirstAnimFrame(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,15 +429,19 @@ void CWindowManager::refreshDirtyWindows() {
|
||||||
if (window.getRealSize().x < window.getEffectiveSize().x || window.getRealSize().y < window.getEffectiveSize().y) {
|
if (window.getRealSize().x < window.getEffectiveSize().x || window.getRealSize().y < window.getEffectiveSize().y) {
|
||||||
Values[0] = (int)window.getEffectiveSize().x;
|
Values[0] = (int)window.getEffectiveSize().x;
|
||||||
Values[1] = (int)window.getEffectiveSize().y;
|
Values[1] = (int)window.getEffectiveSize().y;
|
||||||
|
if (VECTORDELTANONZERO(window.getLastUpdateSize(), Vector2D(Values[0], Values[1]))) {
|
||||||
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
|
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, Values);
|
||||||
|
window.setLastUpdateSize(Vector2D(Values[0], Values[1]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applyShapeToWindow(&window);
|
applyShapeToWindow(&window);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug::log(LOG, "Refreshed dirty windows.");
|
Debug::log(LOG, "Refreshed dirty windows in " + std::to_string(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - START).count()) + "us.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWindowManager::setFocusedWindow(xcb_drawable_t window) {
|
void CWindowManager::setFocusedWindow(xcb_drawable_t window) {
|
||||||
|
@ -679,24 +702,29 @@ void CWindowManager::setEffectiveSizePosUsingConfig(CWindow* pWindow) {
|
||||||
if (!pWindow || pWindow->getIsFloating())
|
if (!pWindow || pWindow->getIsFloating())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto START = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
const auto MONITOR = getMonitorFromWindow(pWindow);
|
const auto MONITOR = getMonitorFromWindow(pWindow);
|
||||||
const auto BARHEIGHT = (MONITOR->ID == ConfigManager::getInt("bar:monitor") ? (ConfigManager::getInt("bar:enabled") == 1 ? ConfigManager::getInt("bar:height") : ConfigManager::parseError == "" ? 0 : ConfigManager::getInt("bar:height")) : 0);
|
const auto BARHEIGHT = (MONITOR->ID == ConfigManager::getInt("bar:monitor") ? (ConfigManager::getInt("bar:enabled") == 1 ? ConfigManager::getInt("bar:height") : ConfigManager::parseError == "" ? 0 : ConfigManager::getInt("bar:height")) : 0);
|
||||||
|
|
||||||
|
|
||||||
// set some flags.
|
// set some flags.
|
||||||
const bool DISPLAYLEFT = STICKS(pWindow->getPosition().x, MONITOR->vecPosition.x);
|
const bool DISPLAYLEFT = STICKS(pWindow->getPosition().x, MONITOR->vecPosition.x);
|
||||||
const bool DISPLAYRIGHT = STICKS(pWindow->getPosition().x + pWindow->getSize().x, MONITOR->vecPosition.x + MONITOR->vecSize.x);
|
const bool DISPLAYRIGHT = STICKS(pWindow->getPosition().x + pWindow->getSize().x, MONITOR->vecPosition.x + MONITOR->vecSize.x);
|
||||||
const bool DISPLAYTOP = STICKS(pWindow->getPosition().y, MONITOR->vecPosition.y);
|
const bool DISPLAYTOP = STICKS(pWindow->getPosition().y, MONITOR->vecPosition.y);
|
||||||
const bool DISPLAYBOTTOM = STICKS(pWindow->getPosition().y + pWindow->getSize().y, MONITOR->vecPosition.y + MONITOR->vecSize.y);
|
const bool DISPLAYBOTTOM = STICKS(pWindow->getPosition().y + pWindow->getSize().y, MONITOR->vecPosition.y + MONITOR->vecSize.y);
|
||||||
|
|
||||||
pWindow->setEffectivePosition(pWindow->getPosition() + Vector2D(ConfigManager::getInt("border_size"), ConfigManager::getInt("border_size")));
|
const auto BORDERSIZE = ConfigManager::getInt("border_size");
|
||||||
pWindow->setEffectiveSize(pWindow->getSize() - (Vector2D(ConfigManager::getInt("border_size"), ConfigManager::getInt("border_size")) * 2));
|
const auto GAPSOUT = ConfigManager::getInt("gaps_out");
|
||||||
|
const auto GAPSIN = ConfigManager::getInt("gaps_in");
|
||||||
|
|
||||||
const auto OFFSETTOPLEFT = Vector2D(DISPLAYLEFT ? ConfigManager::getInt("gaps_out") + MONITOR->vecReservedTopLeft.x : ConfigManager::getInt("gaps_in"),
|
pWindow->setEffectivePosition(pWindow->getPosition() + Vector2D(BORDERSIZE, BORDERSIZE));
|
||||||
DISPLAYTOP ? ConfigManager::getInt("gaps_out") + MONITOR->vecReservedTopLeft.y + BARHEIGHT : ConfigManager::getInt("gaps_in"));
|
pWindow->setEffectiveSize(pWindow->getSize() - (Vector2D(BORDERSIZE, BORDERSIZE) * 2));
|
||||||
|
|
||||||
const auto OFFSETBOTTOMRIGHT = Vector2D( DISPLAYRIGHT ? ConfigManager::getInt("gaps_out") + MONITOR->vecReservedBottomRight.x : ConfigManager::getInt("gaps_in"),
|
const auto OFFSETTOPLEFT = Vector2D(DISPLAYLEFT ? GAPSOUT + MONITOR->vecReservedTopLeft.x : GAPSIN,
|
||||||
DISPLAYBOTTOM ? ConfigManager::getInt("gaps_out") + MONITOR->vecReservedBottomRight.y : ConfigManager::getInt("gaps_in"));
|
DISPLAYTOP ? GAPSOUT + MONITOR->vecReservedTopLeft.y + BARHEIGHT : GAPSIN);
|
||||||
|
|
||||||
|
const auto OFFSETBOTTOMRIGHT = Vector2D( DISPLAYRIGHT ? GAPSOUT + MONITOR->vecReservedBottomRight.x : GAPSIN,
|
||||||
|
DISPLAYBOTTOM ? GAPSOUT + MONITOR->vecReservedBottomRight.y : GAPSIN);
|
||||||
|
|
||||||
// do gaps, set top left
|
// do gaps, set top left
|
||||||
pWindow->setEffectivePosition(pWindow->getEffectivePosition() + OFFSETTOPLEFT);
|
pWindow->setEffectivePosition(pWindow->getEffectivePosition() + OFFSETTOPLEFT);
|
||||||
|
|
Loading…
Reference in a new issue