mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-25 14:25:58 +01:00
Added a cairo bar. READ THE COMMIT DESC.
I have had this crash my WM on boot once in a blue moon. This happens rarely and should NOT happen when the WM is already running. If anyone has a solution, feel free to contribute. If you want to be 100% safe, use bar_enabled=0 in the config.
This commit is contained in:
parent
005265404a
commit
c8c879f103
13 changed files with 147 additions and 84 deletions
|
@ -8,6 +8,9 @@ add_compile_options(-std=c++17)
|
||||||
add_compile_options(-Wall -Wextra)
|
add_compile_options(-Wall -Wextra)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0 harfbuzz cairo gdk)
|
||||||
|
|
||||||
file(GLOB_RECURSE SRCFILES "src/*.cpp")
|
file(GLOB_RECURSE SRCFILES "src/*.cpp")
|
||||||
|
|
||||||
add_executable(Hypr ${SRCFILES})
|
add_executable(Hypr ${SRCFILES})
|
||||||
|
@ -18,6 +21,8 @@ set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||||
include(CPack)
|
include(CPack)
|
||||||
|
|
||||||
|
target_link_libraries(Hypr PkgConfig::deps)
|
||||||
|
|
||||||
target_link_libraries(Hypr
|
target_link_libraries(Hypr
|
||||||
xcb
|
xcb
|
||||||
xcb-ewmh
|
xcb-ewmh
|
||||||
|
|
|
@ -23,7 +23,7 @@ Hypr is a Linux tiling window manager for Xorg. It's written in XCB with modern
|
||||||
- Moving / Fullscreening windows
|
- Moving / Fullscreening windows
|
||||||
|
|
||||||
## Roadmap v2 (not in order)
|
## Roadmap v2 (not in order)
|
||||||
- [ ] Upgrade the status bar rendering to Cairo
|
- [x] Upgrade the status bar rendering to Cairo
|
||||||
- [ ] Better status bar configability
|
- [ ] Better status bar configability
|
||||||
- [ ] Rounded corners
|
- [ ] Rounded corners
|
||||||
- [x] Replace default X11 cursor with the pointer
|
- [x] Replace default X11 cursor with the pointer
|
||||||
|
|
|
@ -7,6 +7,8 @@ gaps_in=5
|
||||||
border_size=1
|
border_size=1
|
||||||
gaps_out=20
|
gaps_out=20
|
||||||
bar_height=20
|
bar_height=20
|
||||||
|
bar_monitor=0
|
||||||
|
bar_enabled=1
|
||||||
max_fps=60
|
max_fps=60
|
||||||
|
|
||||||
# colors
|
# colors
|
||||||
|
|
|
@ -95,13 +95,13 @@ void KeybindManager::killactive(std::string args) {
|
||||||
void KeybindManager::call(std::string args) {
|
void KeybindManager::call(std::string args) {
|
||||||
|
|
||||||
if (fork() == 0) {
|
if (fork() == 0) {
|
||||||
//setsid();
|
setsid();
|
||||||
|
|
||||||
execl("/bin/sh", "/bin/sh", "-c", args.c_str(), nullptr);
|
execl("/bin/sh", "/bin/sh", "-c", args.c_str(), nullptr);
|
||||||
|
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
//wait(NULL);
|
wait(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeybindManager::movewindow(std::string arg) {
|
void KeybindManager::movewindow(std::string arg) {
|
||||||
|
|
109
src/bar/Bar.cpp
109
src/bar/Bar.cpp
|
@ -6,6 +6,7 @@
|
||||||
#include "../windowManager.hpp"
|
#include "../windowManager.hpp"
|
||||||
|
|
||||||
void CStatusBar::setup(int MonitorID) {
|
void CStatusBar::setup(int MonitorID) {
|
||||||
|
Debug::log(LOG, "Creating the bar!");
|
||||||
|
|
||||||
if (MonitorID > g_pWindowManager->monitors.size()) {
|
if (MonitorID > g_pWindowManager->monitors.size()) {
|
||||||
MonitorID = 0;
|
MonitorID = 0;
|
||||||
|
@ -42,20 +43,30 @@ void CStatusBar::setup(int MonitorID) {
|
||||||
auto contextBG = &m_mContexts["BG"];
|
auto contextBG = &m_mContexts["BG"];
|
||||||
contextBG->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
contextBG->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
||||||
|
|
||||||
values[0] = 0x111111;
|
values[0] = 0xFF111111;
|
||||||
values[1] = 0x111111;
|
values[1] = 0xFF111111;
|
||||||
xcb_create_gc(g_pWindowManager->DisplayConnection, contextBG->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, values);
|
xcb_create_gc(g_pWindowManager->DisplayConnection, contextBG->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, values);
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
|
auto contextBGT = &m_mContexts["BGT"];
|
||||||
|
contextBGT->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
||||||
|
|
||||||
|
values[0] = 0x00000000;
|
||||||
|
values[1] = 0x00000000;
|
||||||
|
xcb_create_gc(g_pWindowManager->DisplayConnection, contextBGT->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, values);
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
auto contextBASETEXT = &m_mContexts["BASETEXT"];
|
auto contextBASETEXT = &m_mContexts["BASETEXT"];
|
||||||
|
|
||||||
contextBASETEXT->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
contextBASETEXT->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
||||||
contextBASETEXT->Font = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
contextBASETEXT->Font = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
||||||
xcb_open_font(g_pWindowManager->DisplayConnection, contextBASETEXT->Font, 5, "fixed");
|
xcb_open_font(g_pWindowManager->DisplayConnection, contextBASETEXT->Font, 5, "fixed");
|
||||||
values[0] = 0xFFFFFF;
|
values[0] = 0xFFFFFFFF;
|
||||||
values[1] = 0x111111;
|
values[1] = 0xFF111111;
|
||||||
values[2] = contextBASETEXT->Font;
|
values[2] = contextBASETEXT->Font;
|
||||||
|
|
||||||
xcb_create_gc(g_pWindowManager->DisplayConnection, contextBASETEXT->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND | XCB_GC_FONT, values);
|
xcb_create_gc(g_pWindowManager->DisplayConnection, contextBASETEXT->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND | XCB_GC_FONT, values);
|
||||||
|
@ -66,8 +77,8 @@ void CStatusBar::setup(int MonitorID) {
|
||||||
auto contextHITEXT = &m_mContexts["HITEXT"];
|
auto contextHITEXT = &m_mContexts["HITEXT"];
|
||||||
contextHITEXT->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
contextHITEXT->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
||||||
contextHITEXT->Font = contextBASETEXT->Font;
|
contextHITEXT->Font = contextBASETEXT->Font;
|
||||||
values[0] = 0x000000;
|
values[0] = 0xFF000000;
|
||||||
values[1] = 0xFF3333;
|
values[1] = 0xFFFF3333;
|
||||||
values[2] = contextHITEXT->Font;
|
values[2] = contextHITEXT->Font;
|
||||||
|
|
||||||
xcb_create_gc(g_pWindowManager->DisplayConnection, contextHITEXT->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND | XCB_GC_FONT, values);
|
xcb_create_gc(g_pWindowManager->DisplayConnection, contextHITEXT->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND | XCB_GC_FONT, values);
|
||||||
|
@ -78,20 +89,22 @@ void CStatusBar::setup(int MonitorID) {
|
||||||
auto contextMEDBG = &m_mContexts["MEDBG"];
|
auto contextMEDBG = &m_mContexts["MEDBG"];
|
||||||
contextMEDBG->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
contextMEDBG->GContext = xcb_generate_id(g_pWindowManager->DisplayConnection);
|
||||||
|
|
||||||
values[0] = 0xFF3333;
|
values[0] = 0xFFFF3333;
|
||||||
values[1] = 0x111111;
|
values[1] = 0xFF111111;
|
||||||
xcb_create_gc(g_pWindowManager->DisplayConnection, contextMEDBG->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, values);
|
xcb_create_gc(g_pWindowManager->DisplayConnection, contextMEDBG->GContext, m_iPixmap, XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, values);
|
||||||
|
|
||||||
// don't, i use it later
|
// don't, i use it later
|
||||||
//xcb_close_font(g_pWindowManager->DisplayConnection, contextBASETEXT->Font);
|
//xcb_close_font(g_pWindowManager->DisplayConnection, contextBASETEXT->Font);
|
||||||
|
|
||||||
|
m_pCairoSurface = cairo_xcb_surface_create(g_pWindowManager->DisplayConnection, m_iPixmap, g_pWindowManager->VisualType,
|
||||||
// Set the bar to be top
|
m_vecSize.x, m_vecSize.y);
|
||||||
//values[0] = XCB_STACK_MODE_ABOVE;
|
m_pCairo = cairo_create(m_pCairoSurface);
|
||||||
//xcb_configure_window(g_pWindowManager->DisplayConnection, m_iWindowID, XCB_CONFIG_WINDOW_STACK_MODE, values);
|
cairo_surface_destroy(m_pCairoSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CStatusBar::destroy() {
|
void CStatusBar::destroy() {
|
||||||
|
Debug::log(LOG, "Destroying the bar!");
|
||||||
|
|
||||||
xcb_close_font(g_pWindowManager->DisplayConnection, m_mContexts["HITEXT"].Font);
|
xcb_close_font(g_pWindowManager->DisplayConnection, m_mContexts["HITEXT"].Font);
|
||||||
xcb_destroy_window(g_pWindowManager->DisplayConnection, m_iWindowID);
|
xcb_destroy_window(g_pWindowManager->DisplayConnection, m_iWindowID);
|
||||||
xcb_destroy_window(g_pWindowManager->DisplayConnection, m_iPixmap);
|
xcb_destroy_window(g_pWindowManager->DisplayConnection, m_iPixmap);
|
||||||
|
@ -100,52 +113,48 @@ void CStatusBar::destroy() {
|
||||||
xcb_free_gc(g_pWindowManager->DisplayConnection, m_mContexts["MEDBG"].GContext);
|
xcb_free_gc(g_pWindowManager->DisplayConnection, m_mContexts["MEDBG"].GContext);
|
||||||
xcb_free_gc(g_pWindowManager->DisplayConnection, m_mContexts["TEXT"].GContext);
|
xcb_free_gc(g_pWindowManager->DisplayConnection, m_mContexts["TEXT"].GContext);
|
||||||
xcb_free_gc(g_pWindowManager->DisplayConnection, m_mContexts["HITEXT"].GContext);
|
xcb_free_gc(g_pWindowManager->DisplayConnection, m_mContexts["HITEXT"].GContext);
|
||||||
|
|
||||||
|
// Free cairo
|
||||||
|
cairo_destroy(m_pCairo);
|
||||||
|
m_pCairo = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getTextWidth(std::string text, xcb_font_t font) {
|
int CStatusBar::getTextWidth(std::string text) {
|
||||||
|
cairo_select_font_face(m_pCairo, "Noto Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
||||||
|
cairo_set_font_size(m_pCairo, 12);
|
||||||
|
|
||||||
// conv from utf8 to UCS-2 (what the fuck Xorg why)
|
cairo_text_extents_t textextents;
|
||||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> strCnv;
|
cairo_text_extents(m_pCairo, text.c_str(), &textextents);
|
||||||
std::wstring wideString = strCnv.from_bytes(text);
|
|
||||||
|
|
||||||
// create a xcb string
|
return textextents.width + 1 /* pad */;
|
||||||
xcb_char2b_t bytes[wideString.length()];
|
}
|
||||||
|
|
||||||
for (int i = 0; i < wideString.length(); ++i) {
|
void CStatusBar::drawText(Vector2D pos, std::string text, uint32_t color) {
|
||||||
bytes[i].byte1 = 0x0; // Only ASCII support. TODO: Maybe more?
|
cairo_select_font_face(m_pCairo, "Noto Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
||||||
bytes[i].byte2 = wideString[i] & 0xFF;
|
cairo_set_font_size(m_pCairo, 12);
|
||||||
}
|
cairo_set_source_rgba(m_pCairo, RED(color), GREEN(color), BLUE(color), ALPHA(color));
|
||||||
|
cairo_move_to(m_pCairo, pos.x, pos.y);
|
||||||
xcb_generic_error_t* error;
|
cairo_show_text(m_pCairo, text.c_str());
|
||||||
const auto COOKIE = xcb_query_text_extents(g_pWindowManager->DisplayConnection, font, wideString.length() - 1, (xcb_char2b_t*)bytes);
|
|
||||||
xcb_query_text_extents_reply_t* reply = xcb_query_text_extents_reply(g_pWindowManager->DisplayConnection, COOKIE, &error);
|
|
||||||
if (!reply) {
|
|
||||||
Debug::log(ERR, "Text extent failed, code " + std::to_string(error->error_code));
|
|
||||||
free(error);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto WIDTH = reply->overall_width;
|
|
||||||
free(reply);
|
|
||||||
return WIDTH + 5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CStatusBar::draw() {
|
void CStatusBar::draw() {
|
||||||
|
|
||||||
// update animations.
|
|
||||||
AnimationUtil::move();
|
|
||||||
|
|
||||||
const auto WORKSPACE = g_pWindowManager->getWorkspaceByID(g_pWindowManager->activeWorkspaces[m_iMonitorID]);
|
const auto WORKSPACE = g_pWindowManager->getWorkspaceByID(g_pWindowManager->activeWorkspaces[m_iMonitorID]);
|
||||||
|
|
||||||
if (!WORKSPACE || WORKSPACE->getHasFullscreenWindow()) // TODO: fix this
|
if (!WORKSPACE || WORKSPACE->getHasFullscreenWindow()) // TODO: fix this
|
||||||
return; // Do not draw a bar on a fullscreen window.
|
return; // Do not draw a bar on a fullscreen window.
|
||||||
|
|
||||||
|
if (!m_pCairo) {
|
||||||
|
Debug::log(ERR, "Cairo is null but attempted to draw!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
xcb_rectangle_t rectangles[] = {{(int)0, (int)0, (int)m_vecSize.x, (int)m_vecSize.y}};
|
xcb_rectangle_t rectangles[] = {{(int)0, (int)0, (int)m_vecSize.x, (int)m_vecSize.y}};
|
||||||
xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, m_mContexts["BG"].GContext, 1, rectangles);
|
xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, m_mContexts["BG"].GContext, 1, rectangles);
|
||||||
|
|
||||||
// Draw workspaces
|
// Draw workspaces
|
||||||
int drawnWorkspaces = 0;
|
int drawnWorkspaces = 0;
|
||||||
for (int i = 0; i < openWorkspaces.size(); ++i) {
|
for (long unsigned int i = 0; i < openWorkspaces.size(); ++i) {
|
||||||
|
|
||||||
const auto WORKSPACE = openWorkspaces[i];
|
const auto WORKSPACE = openWorkspaces[i];
|
||||||
|
|
||||||
|
@ -157,14 +166,11 @@ void CStatusBar::draw() {
|
||||||
|
|
||||||
std::string workspaceName = std::to_string(openWorkspaces[i]);
|
std::string workspaceName = std::to_string(openWorkspaces[i]);
|
||||||
|
|
||||||
if (WORKSPACE == MOUSEWORKSPACEID) {
|
|
||||||
xcb_rectangle_t rectangleActive[] = { { m_vecSize.y * drawnWorkspaces, 0, m_vecSize.y, m_vecSize.y } };
|
xcb_rectangle_t rectangleActive[] = { { m_vecSize.y * drawnWorkspaces, 0, m_vecSize.y, m_vecSize.y } };
|
||||||
xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, m_mContexts["MEDBG"].GContext, 1, rectangleActive);
|
xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, WORKSPACE == MOUSEWORKSPACEID ? m_mContexts["MEDBG"].GContext : m_mContexts["BG"].GContext, 1, rectangleActive);
|
||||||
}
|
|
||||||
|
|
||||||
xcb_image_text_8(g_pWindowManager->DisplayConnection, workspaceName.length(), m_iPixmap,
|
drawText(Vector2D(m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - getTextWidth(workspaceName) / 2.f, m_vecSize.y - (m_vecSize.y - 9) / 2.f),
|
||||||
WORKSPACE == MOUSEWORKSPACEID ? m_mContexts["HITEXT"].GContext : m_mContexts["BASETEXT"].GContext,
|
workspaceName, WORKSPACE == MOUSEWORKSPACEID ? 0xFF111111 : 0xFFFFFFFF);
|
||||||
m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - (WORKSPACE > 9 ? 4 : 2), m_vecSize.y - (m_vecSize.y - 10) / 2, workspaceName.c_str());
|
|
||||||
|
|
||||||
drawnWorkspaces++;
|
drawnWorkspaces++;
|
||||||
}
|
}
|
||||||
|
@ -173,14 +179,19 @@ void CStatusBar::draw() {
|
||||||
std::string STATUS = exec(m_szStatusCommand.c_str());
|
std::string STATUS = exec(m_szStatusCommand.c_str());
|
||||||
STATUS = STATUS.substr(0, (STATUS.length() > 0 ? STATUS.length() - 1 : 9999999));
|
STATUS = STATUS.substr(0, (STATUS.length() > 0 ? STATUS.length() - 1 : 9999999));
|
||||||
if (STATUS != "") {
|
if (STATUS != "") {
|
||||||
xcb_image_text_8(g_pWindowManager->DisplayConnection, STATUS.length(), m_iPixmap,
|
drawText(Vector2D(m_vecSize.x - getTextWidth(STATUS), m_vecSize.y - (m_vecSize.y - 9) / 2.f),
|
||||||
m_mContexts["BASETEXT"].GContext, m_vecSize.x - getTextWidth(STATUS, m_mContexts["BASETEXT"].Font), (m_vecSize.y - (m_vecSize.y - 10) / 2),
|
STATUS, 0xFFFFFFFF);
|
||||||
STATUS.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
xcb_flush(g_pWindowManager->DisplayConnection);
|
cairo_surface_flush(m_pCairoSurface);
|
||||||
|
|
||||||
|
// clear before copying
|
||||||
|
//xcb_clear_area(g_pWindowManager->DisplayConnection, 0, m_iWindowID, 0, 0, m_vecSize.x, m_vecSize.y);
|
||||||
|
//xcb_flush(g_pWindowManager->DisplayConnection);
|
||||||
|
|
||||||
xcb_copy_area(g_pWindowManager->DisplayConnection, m_iPixmap, m_iWindowID, m_mContexts["BG"].GContext,
|
xcb_copy_area(g_pWindowManager->DisplayConnection, m_iPixmap, m_iWindowID, m_mContexts["BG"].GContext,
|
||||||
0, 0, 0, 0, m_vecSize.x, m_vecSize.y);
|
0, 0, 0, 0, m_vecSize.x, m_vecSize.y);
|
||||||
|
|
||||||
|
xcb_flush(g_pWindowManager->DisplayConnection);
|
||||||
}
|
}
|
|
@ -30,5 +30,14 @@ private:
|
||||||
|
|
||||||
xcb_pixmap_t m_iPixmap;
|
xcb_pixmap_t m_iPixmap;
|
||||||
|
|
||||||
|
|
||||||
|
// Cairo
|
||||||
|
|
||||||
|
cairo_surface_t* m_pCairoSurface = nullptr;
|
||||||
|
cairo_t* m_pCairo = nullptr;
|
||||||
|
|
||||||
|
void drawText(Vector2D, std::string, uint32_t);
|
||||||
|
int getTextWidth(std::string);
|
||||||
|
|
||||||
std::unordered_map<std::string, SDrawingContext> m_mContexts;
|
std::unordered_map<std::string, SDrawingContext> m_mContexts;
|
||||||
};
|
};
|
|
@ -17,6 +17,7 @@ void ConfigManager::init() {
|
||||||
configValues["max_fps"].intValue = 60;
|
configValues["max_fps"].intValue = 60;
|
||||||
|
|
||||||
configValues["bar_monitor"].intValue = 0;
|
configValues["bar_monitor"].intValue = 0;
|
||||||
|
configValues["bar_enabled"].intValue = 1;
|
||||||
configValues["bar_height"].intValue = 15;
|
configValues["bar_height"].intValue = 15;
|
||||||
|
|
||||||
configValues["status_command"].strValue = "date +%I:%M\\ %p"; // Time
|
configValues["status_command"].strValue = "date +%I:%M\\ %p"; // Time
|
||||||
|
|
|
@ -13,6 +13,12 @@
|
||||||
#include <xcb/xcb_util.h>
|
#include <xcb/xcb_util.h>
|
||||||
#include <xcb/xcb_cursor.h>
|
#include <xcb/xcb_cursor.h>
|
||||||
|
|
||||||
|
#include <cairo/cairo.h>
|
||||||
|
#include <cairo/cairo-xcb.h>
|
||||||
|
#include <glib-2.0/glib.h>
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -58,3 +64,7 @@
|
||||||
|
|
||||||
#define HYPRATOM(name) {name, 0}
|
#define HYPRATOM(name) {name, 0}
|
||||||
|
|
||||||
|
#define ALPHA(c) ((double)(((c) >> 24) & 0xff) / 255.0)
|
||||||
|
#define RED(c) ((double)(((c) >> 16) & 0xff) / 255.0)
|
||||||
|
#define GREEN(c) ((double)(((c) >> 8) & 0xff) / 255.0)
|
||||||
|
#define BLUE(c) ((double)(((c)) & 0xff) / 255.0)
|
|
@ -1,20 +1,50 @@
|
||||||
#include "events.hpp"
|
#include "events.hpp"
|
||||||
|
|
||||||
void handle() {
|
gpointer handle(gpointer data) {
|
||||||
|
while (1) {
|
||||||
|
// wait for the main thread to be idle
|
||||||
|
while (g_pWindowManager->mainThreadBusy) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set state to let the main thread know to wait.
|
||||||
|
g_pWindowManager->animationUtilBusy = true;
|
||||||
|
|
||||||
|
// draw bar
|
||||||
g_pWindowManager->statusBar.draw();
|
g_pWindowManager->statusBar.draw();
|
||||||
|
|
||||||
// check config
|
// check config
|
||||||
ConfigManager::tick();
|
ConfigManager::tick();
|
||||||
|
|
||||||
|
// update animations.
|
||||||
|
AnimationUtil::move();
|
||||||
|
//
|
||||||
|
|
||||||
|
// restore anim state
|
||||||
|
g_pWindowManager->animationUtilBusy = false;
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / ConfigManager::getInt("max_fps")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::setThread() {
|
void Events::setThread() {
|
||||||
|
|
||||||
g_pWindowManager->barThread = new std::thread([&]() {
|
// Start a GTK thread so that Cairo does not complain.
|
||||||
|
gdk_threads_enter();
|
||||||
|
|
||||||
|
g_pWindowManager->barThread = g_thread_new("Bar", handle, nullptr);
|
||||||
|
|
||||||
|
if (!g_pWindowManager->barThread) {
|
||||||
|
Debug::log(ERR, "Gthread failed!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*g_pWindowManager->barThread = new std::thread([&]() {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
handle();
|
handle();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / ConfigManager::getInt("max_fps")));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000 / ConfigManager::getInt("max_fps")));
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::eventEnter(xcb_generic_event_t* event) {
|
void Events::eventEnter(xcb_generic_event_t* event) {
|
||||||
|
@ -23,8 +53,9 @@ void Events::eventEnter(xcb_generic_event_t* event) {
|
||||||
// Just focus it and update.
|
// Just focus it and update.
|
||||||
g_pWindowManager->setFocusedWindow(E->event);
|
g_pWindowManager->setFocusedWindow(E->event);
|
||||||
|
|
||||||
// vvv insallah no segfaults
|
if(const auto PENTERWINDOW = g_pWindowManager->getWindowFromDrawable(E->event)) {
|
||||||
g_pWindowManager->getWindowFromDrawable(E->event)->setDirty(true);
|
PENTERWINDOW->setDirty(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Events::eventLeave(xcb_generic_event_t* event) {
|
void Events::eventLeave(xcb_generic_event_t* event) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ Started by Vaxry on 2021 / 11 / 17
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "windowManager.hpp"
|
#include "windowManager.hpp"
|
||||||
|
#include "defines.hpp"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
clearLogs();
|
clearLogs();
|
||||||
|
@ -51,6 +52,8 @@ int main(int argc, char** argv) {
|
||||||
|
|
||||||
xcb_disconnect(g_pWindowManager->DisplayConnection);
|
xcb_disconnect(g_pWindowManager->DisplayConnection);
|
||||||
|
|
||||||
|
gdk_threads_leave();
|
||||||
|
|
||||||
if (const auto err = xcb_connection_has_error(g_pWindowManager->DisplayConnection); err != 0) {
|
if (const auto err = xcb_connection_has_error(g_pWindowManager->DisplayConnection); err != 0) {
|
||||||
Debug::log(CRIT, "Exiting because of error " + std::to_string(err));
|
Debug::log(CRIT, "Exiting because of error " + std::to_string(err));
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -6,14 +6,6 @@ void AnimationUtil::move() {
|
||||||
static std::chrono::time_point lastFrame = std::chrono::high_resolution_clock::now();
|
static std::chrono::time_point lastFrame = std::chrono::high_resolution_clock::now();
|
||||||
const double DELTA = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - lastFrame).count();
|
const double DELTA = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - lastFrame).count();
|
||||||
|
|
||||||
// wait for the main thread to be idle
|
|
||||||
while (g_pWindowManager->mainThreadBusy) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set state to let the main thread know to wait.
|
|
||||||
g_pWindowManager->animationUtilBusy = true;
|
|
||||||
|
|
||||||
const double ANIMATIONSPEED = ((double)1 / (double)ConfigManager::getFloat("anim.speed")) * DELTA;
|
const double ANIMATIONSPEED = ((double)1 / (double)ConfigManager::getFloat("anim.speed")) * DELTA;
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,8 +58,5 @@ void AnimationUtil::move() {
|
||||||
if (updateRequired)
|
if (updateRequired)
|
||||||
emptyEvent(); // send a fake request to update dirty windows
|
emptyEvent(); // send a fake request to update dirty windows
|
||||||
|
|
||||||
// restore anim state
|
|
||||||
g_pWindowManager->animationUtilBusy = false;
|
|
||||||
|
|
||||||
lastFrame = std::chrono::high_resolution_clock::now();
|
lastFrame = std::chrono::high_resolution_clock::now();
|
||||||
}
|
}
|
|
@ -154,6 +154,7 @@ void CWindowManager::setupManager() {
|
||||||
|
|
||||||
// ---- INIT THE BAR ---- //
|
// ---- INIT THE BAR ---- //
|
||||||
|
|
||||||
|
if (ConfigManager::getInt("bar_enabled") == 1) {
|
||||||
for (auto& monitor : monitors) {
|
for (auto& monitor : monitors) {
|
||||||
if (monitor.primary) {
|
if (monitor.primary) {
|
||||||
statusBar.setup(ConfigManager::configValues["bar_monitor"].intValue);
|
statusBar.setup(ConfigManager::configValues["bar_monitor"].intValue);
|
||||||
|
@ -165,6 +166,7 @@ void CWindowManager::setupManager() {
|
||||||
|
|
||||||
// start its' update thread
|
// start its' update thread
|
||||||
Events::setThread();
|
Events::setThread();
|
||||||
|
}
|
||||||
|
|
||||||
Debug::log(LOG, "Bar done.");
|
Debug::log(LOG, "Bar done.");
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
std::vector<int> activeWorkspaces;
|
std::vector<int> activeWorkspaces;
|
||||||
|
|
||||||
CStatusBar statusBar;
|
CStatusBar statusBar;
|
||||||
std::thread* barThread;
|
GThread* barThread;
|
||||||
|
|
||||||
std::atomic<bool> mainThreadBusy = false;
|
std::atomic<bool> mainThreadBusy = false;
|
||||||
std::atomic<bool> animationUtilBusy = false;
|
std::atomic<bool> animationUtilBusy = false;
|
||||||
|
|
Loading…
Reference in a new issue