Added border animations and better config warnings

This commit is contained in:
vaxerski 2021-12-10 21:55:41 +01:00
parent 2ac537a2fa
commit caa967a9b2
6 changed files with 103 additions and 24 deletions

View file

@ -41,6 +41,7 @@ void ConfigManager::init() {
configValues["anim:speed"].floatValue = 1; configValues["anim:speed"].floatValue = 1;
configValues["anim:enabled"].intValue = 0; configValues["anim:enabled"].intValue = 0;
configValues["anim:cheap"].intValue = 1; configValues["anim:cheap"].intValue = 1;
configValues["anim:borders"].intValue = 1;
if (!g_pWindowManager->statusBar) { if (!g_pWindowManager->statusBar) {
isFirstLaunch = true; isFirstLaunch = true;
@ -51,8 +52,10 @@ void ConfigManager::init() {
} }
void configSetValueSafe(const std::string& COMMAND, const std::string& VALUE) { void configSetValueSafe(const std::string& COMMAND, const std::string& VALUE) {
if (ConfigManager::configValues.find(COMMAND) == ConfigManager::configValues.end()) if (ConfigManager::configValues.find(COMMAND) == ConfigManager::configValues.end()) {
ConfigManager::parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">: No such field.";
return; return;
}
auto& CONFIGENTRY = ConfigManager::configValues.at(COMMAND); auto& CONFIGENTRY = ConfigManager::configValues.at(COMMAND);
if (CONFIGENTRY.intValue != -1) { if (CONFIGENTRY.intValue != -1) {
@ -212,11 +215,13 @@ void parseBarLine(const std::string& line) {
// And parse // And parse
// check if command // check if command
const auto EQUALSPLACE = line.find_first_of('='); const auto EQUALSPLACE = line.find_first_of('=');
if (EQUALSPLACE == std::string::npos) if (EQUALSPLACE == std::string::npos)
return; return;
const auto COMMAND = line.substr(0, EQUALSPLACE); const auto COMMAND = line.substr(0, EQUALSPLACE);
const auto VALUE = line.substr(EQUALSPLACE + 1); const auto VALUE = line.substr(EQUALSPLACE + 1);
@ -252,7 +257,7 @@ void parseLine(std::string& line) {
// now, cut the comment off // now, cut the comment off
if (COMMENTSTART != std::string::npos) if (COMMENTSTART != std::string::npos)
line = line.substr(COMMENTSTART); line = line.substr(COMMENTSTART + 1);
// remove shit at the beginning // remove shit at the beginning
while (line[0] == ' ' || line[0] == '\t') { while (line[0] == ' ' || line[0] == '\t') {
@ -300,7 +305,8 @@ void parseLine(std::string& line) {
} else if (COMMAND == "exec") { } else if (COMMAND == "exec") {
handleRawExec(COMMAND, VALUE); handleRawExec(COMMAND, VALUE);
return; return;
} else if (COMMAND == "exec-once" && ConfigManager::isFirstLaunch) { } else if (COMMAND == "exec-once") {
if (ConfigManager::isFirstLaunch)
handleRawExec(COMMAND, VALUE); handleRawExec(COMMAND, VALUE);
return; return;
} else if (COMMAND == "status_command") { } else if (COMMAND == "status_command") {
@ -353,12 +359,12 @@ void ConfigManager::loadConfigLoadVars() {
Debug::log(NONE, line); Debug::log(NONE, line);
parseError = "Config error at line " + std::to_string(linenum) + ": Line parsing error."; parseError = "Config error at line " + std::to_string(linenum) + ": Line parsing error.";
break; //break;
} }
if (parseError != "") { if (parseError != "" && parseError.find("Config error at line") != 0) {
parseError = "Config error at line " + std::to_string(linenum) + ": " + parseError; parseError = "Config error at line " + std::to_string(linenum) + ": " + parseError;
break; //break;
} }
++linenum; ++linenum;

View file

@ -16,6 +16,23 @@ void AnimationUtil::move() {
// check if window needs an animation. // check if window needs an animation.
window.setIsAnimated(false); window.setIsAnimated(false);
// Border animations
if (window.getDrawable() > 0) {
if (window.getEffectiveBorderColor() != window.getRealBorderColor()) {
// interp border color if enabled
if (ConfigManager::getInt("anim:borders") == 1) {
window.setRealBorderColor(parabolicColor(window.getRealBorderColor(), window.getEffectiveBorderColor(), ANIMATIONSPEED));
} else {
window.setRealBorderColor(window.getEffectiveBorderColor());
}
updateRequired = true;
window.setDirty(true);
}
}
if (ConfigManager::getInt("anim:enabled") == 0 || window.getIsFloating()) { if (ConfigManager::getInt("anim:enabled") == 0 || window.getIsFloating()) {
// Disabled animations. instant warps. // Disabled animations. instant warps.

View file

@ -29,6 +29,24 @@ double parabolic(double from, double to, double incline) {
return from + ((to - from) / incline); return from + ((to - from) / incline);
} }
CFloatingColor parabolicColor(CFloatingColor from, uint32_t to, double incline) {
from.r = parabolic(from.r, RED(to) * 255.f, incline);
from.g = parabolic(from.g, GREEN(to) * 255.f, incline);
from.b = parabolic(from.b, BLUE(to) * 255.f, incline);
from.a = parabolic(from.a, ALPHA(to) * 255.f, incline);
return from;
}
CFloatingColor parabolicColor(CFloatingColor from, CFloatingColor to, double incline) {
from.r = parabolic(from.r, to.r, incline);
from.g = parabolic(from.g, to.g, incline);
from.b = parabolic(from.b, to.b, incline);
from.a = parabolic(from.a, to.a, incline);
return from;
}
void emptyEvent(xcb_drawable_t window) { void emptyEvent(xcb_drawable_t window) {
xcb_expose_event_t exposeEvent; xcb_expose_event_t exposeEvent;
exposeEvent.window = window; exposeEvent.window = window;

View file

@ -2,6 +2,39 @@
#include "../defines.hpp" #include "../defines.hpp"
#include <fstream> #include <fstream>
#include <math.h>
// For precise colors
class CFloatingColor {
public:
float r = 0;
float g = 0;
float b = 0;
float a = 255;
uint32_t getAsUint32() {
return ((int)round(a)) * 0x1000000 + ((int)round(r)) * 0x10000 + ((int)round(g)) * 0x100 + ((int)round(b));
}
CFloatingColor(uint32_t c) {
r = RED(c) * 255.f;
g = GREEN(c) * 255.f;
b = BLUE(c) * 255.f;
a = ALPHA(c) * 255.f;
}
CFloatingColor() {
;
}
bool operator==(CFloatingColor B) {
return r == B.r && g == B.g && b == B.b && a == B.a;
}
bool operator!=(CFloatingColor B) {
return !(r == B.r && g == B.g && b == B.b && a == B.a);
}
};
std::string exec(const char* cmd); std::string exec(const char* cmd);
void clearLogs(); void clearLogs();
@ -9,6 +42,9 @@ void emptyEvent(xcb_drawable_t window = 0);
void wakeUpEvent(xcb_drawable_t window); void wakeUpEvent(xcb_drawable_t window);
bool xcbContainsAtom(xcb_get_property_reply_t* PROP, xcb_atom_t ATOM); bool xcbContainsAtom(xcb_get_property_reply_t* PROP, xcb_atom_t ATOM);
CFloatingColor parabolicColor(CFloatingColor from, uint32_t to, double incline);
CFloatingColor parabolicColor(CFloatingColor from, CFloatingColor to, double incline);
double parabolic(double from, double to, double incline); double parabolic(double from, double to, double incline);
std::vector<std::string> splitString(std::string, char); std::vector<std::string> splitString(std::string, char);

View file

@ -2,6 +2,7 @@
#include "defines.hpp" #include "defines.hpp"
#include "utilities/Workspace.hpp" #include "utilities/Workspace.hpp"
#include "utilities/Util.hpp"
class CWindow { class CWindow {
public: public:
@ -83,6 +84,10 @@ public:
// Weird shenaningans // Weird shenaningans
EXPOSED_MEMBER(IsSleeping, bool, b); EXPOSED_MEMBER(IsSleeping, bool, b);
// Animate borders
EXPOSED_MEMBER(RealBorderColor, CFloatingColor, c);
EXPOSED_MEMBER(EffectiveBorderColor, CFloatingColor, c);
private: private:
}; };

View file

@ -366,7 +366,7 @@ void CWindowManager::refreshDirtyWindows() {
Values[0] = 0; Values[0] = 0;
xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_BORDER_WIDTH, Values); xcb_configure_window(DisplayConnection, window.getDrawable(), XCB_CONFIG_WINDOW_BORDER_WIDTH, Values);
Values[0] = 0x555555; // GRAY :) Values[0] = window.getRealBorderColor().getAsUint32();
xcb_change_window_attributes(DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values); xcb_change_window_attributes(DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values);
const auto MONITOR = getMonitorFromWindow(&window); const auto MONITOR = getMonitorFromWindow(&window);
@ -394,14 +394,10 @@ void CWindowManager::refreshDirtyWindows() {
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);
// Focused special border.
if (window.getDrawable() == LastWindow) { // do border
Values[0] = ConfigManager::getInt("col.active_border"); Values[0] = window.getRealBorderColor().getAsUint32();
xcb_change_window_attributes(DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values); xcb_change_window_attributes(DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values);
} else {
Values[0] = ConfigManager::getInt("col.inactive_border");
xcb_change_window_attributes(DisplayConnection, window.getDrawable(), XCB_CW_BORDER_PIXEL, Values);
}
// If it isn't animated or we have non-cheap animations, update the real size // If it isn't animated or we have non-cheap animations, update the real size
if (!window.getIsAnimated() || ConfigManager::getInt("anim:cheap") == 0) { if (!window.getIsAnimated() || ConfigManager::getInt("anim:cheap") == 0) {
@ -430,12 +426,13 @@ void CWindowManager::refreshDirtyWindows() {
void CWindowManager::setFocusedWindow(xcb_drawable_t window) { void CWindowManager::setFocusedWindow(xcb_drawable_t window) {
if (window && window != Screen->root) { if (window && window != Screen->root) {
// Fix border from the old window that was in focus. // border color
Values[0] = ConfigManager::getInt("col.inactive_border"); if (const auto PLASTWIN = getWindowFromDrawable(LastWindow); PLASTWIN) {
xcb_change_window_attributes(DisplayConnection, LastWindow, XCB_CW_BORDER_PIXEL, Values); PLASTWIN->setEffectiveBorderColor(CFloatingColor(ConfigManager::getInt("col.inactive_border")));
}
Values[0] = ConfigManager::getInt("col.active_border"); if (const auto PLASTWIN = getWindowFromDrawable(window); PLASTWIN) {
xcb_change_window_attributes(DisplayConnection, window, XCB_CW_BORDER_PIXEL, Values); PLASTWIN->setEffectiveBorderColor(CFloatingColor(ConfigManager::getInt("col.active_border")));
}
float values[1]; float values[1];
if (g_pWindowManager->getWindowFromDrawable(window) && g_pWindowManager->getWindowFromDrawable(window)->getIsFloating()) { if (g_pWindowManager->getWindowFromDrawable(window) && g_pWindowManager->getWindowFromDrawable(window)->getIsFloating()) {