mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-09 23:45:58 +01:00
Merge pull request #391 from dgerblick/focuswindow-options
focuswindow options + other hyprctl bugs I found when testing
This commit is contained in:
commit
f35d513bf5
5 changed files with 97 additions and 36 deletions
|
@ -38,11 +38,11 @@ R"#({
|
||||||
"active": "%s"
|
"active": "%s"
|
||||||
},)#",
|
},)#",
|
||||||
m->ID,
|
m->ID,
|
||||||
m->szName.c_str(),
|
escapeJSONStrings(m->szName).c_str(),
|
||||||
(int)m->vecPixelSize.x, (int)m->vecPixelSize.y,
|
(int)m->vecPixelSize.x, (int)m->vecPixelSize.y,
|
||||||
m->refreshRate,
|
m->refreshRate,
|
||||||
(int)m->vecPosition.x, (int)m->vecPosition.y,
|
(int)m->vecPosition.x, (int)m->vecPosition.y,
|
||||||
m->activeWorkspace, g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName.c_str(),
|
m->activeWorkspace, escapeJSONStrings(g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName).c_str(),
|
||||||
(int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y,
|
(int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y,
|
||||||
m->scale,
|
m->scale,
|
||||||
(int)m->transform,
|
(int)m->transform,
|
||||||
|
@ -86,14 +86,14 @@ R"#({
|
||||||
"title": "%s",
|
"title": "%s",
|
||||||
"pid": %i
|
"pid": %i
|
||||||
},)#",
|
},)#",
|
||||||
&w,
|
w.get(),
|
||||||
(int)w->m_vRealPosition.vec().x, (int)w->m_vRealPosition.vec().y,
|
(int)w->m_vRealPosition.vec().x, (int)w->m_vRealPosition.vec().y,
|
||||||
(int)w->m_vRealSize.vec().x, (int)w->m_vRealSize.vec().y,
|
(int)w->m_vRealSize.vec().x, (int)w->m_vRealSize.vec().y,
|
||||||
w->m_iWorkspaceID, (w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName.c_str() : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID)).c_str()),
|
w->m_iWorkspaceID, escapeJSONStrings(w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID))).c_str(),
|
||||||
(int)w->m_bIsFloating,
|
(int)w->m_bIsFloating,
|
||||||
w->m_iMonitorID,
|
w->m_iMonitorID,
|
||||||
g_pXWaylandManager->getAppIDClass(w.get()).c_str(),
|
escapeJSONStrings(g_pXWaylandManager->getAppIDClass(w.get())).c_str(),
|
||||||
g_pXWaylandManager->getTitle(w.get()).c_str(),
|
escapeJSONStrings(g_pXWaylandManager->getTitle(w.get())).c_str(),
|
||||||
w->getPID()
|
w->getPID()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ R"#({
|
||||||
for (auto& w : g_pCompositor->m_vWindows) {
|
for (auto& w : g_pCompositor->m_vWindows) {
|
||||||
if (w->m_bIsMapped) {
|
if (w->m_bIsMapped) {
|
||||||
result += getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i,%i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\tclass: %s\n\ttitle: %s\n\tpid: %i\n\n",
|
result += getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i,%i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\tclass: %s\n\ttitle: %s\n\tpid: %i\n\n",
|
||||||
&w, w->m_szTitle.c_str(), (int)w->m_vRealPosition.vec().x, (int)w->m_vRealPosition.vec().y, (int)w->m_vRealSize.vec().x, (int)w->m_vRealSize.vec().y, w->m_iWorkspaceID, (w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName.c_str() : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID)).c_str()), (int)w->m_bIsFloating, w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w.get()).c_str(), g_pXWaylandManager->getTitle(w.get()).c_str(), w->getPID());
|
w.get(), w->m_szTitle.c_str(), (int)w->m_vRealPosition.vec().x, (int)w->m_vRealPosition.vec().y, (int)w->m_vRealSize.vec().x, (int)w->m_vRealSize.vec().y, w->m_iWorkspaceID, (w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName.c_str() : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID)).c_str()), (int)w->m_bIsFloating, w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w.get()).c_str(), g_pXWaylandManager->getTitle(w.get()).c_str(), w->getPID());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,8 +130,8 @@ R"#({
|
||||||
"hasfullscreen": %i
|
"hasfullscreen": %i
|
||||||
},)#",
|
},)#",
|
||||||
w->m_iID,
|
w->m_iID,
|
||||||
w->m_szName.c_str(),
|
escapeJSONStrings(w->m_szName).c_str(),
|
||||||
g_pCompositor->getMonitorFromID(w->m_iMonitorID)->szName.c_str(),
|
escapeJSONStrings(g_pCompositor->getMonitorFromID(w->m_iMonitorID)->szName).c_str(),
|
||||||
g_pCompositor->getWindowsOnWorkspace(w->m_iID),
|
g_pCompositor->getWindowsOnWorkspace(w->m_iID),
|
||||||
(int)w->m_bHasFullscreenWindow
|
(int)w->m_bHasFullscreenWindow
|
||||||
);
|
);
|
||||||
|
@ -175,11 +175,11 @@ R"#({
|
||||||
PWINDOW,
|
PWINDOW,
|
||||||
(int)PWINDOW->m_vRealPosition.vec().x, (int)PWINDOW->m_vRealPosition.vec().y,
|
(int)PWINDOW->m_vRealPosition.vec().x, (int)PWINDOW->m_vRealPosition.vec().y,
|
||||||
(int)PWINDOW->m_vRealSize.vec().x, (int)PWINDOW->m_vRealSize.vec().y,
|
(int)PWINDOW->m_vRealSize.vec().x, (int)PWINDOW->m_vRealSize.vec().y,
|
||||||
PWINDOW->m_iWorkspaceID, (PWINDOW->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_szName.c_str()),
|
PWINDOW->m_iWorkspaceID, escapeJSONStrings(PWINDOW->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_szName).c_str(),
|
||||||
(int)PWINDOW->m_bIsFloating,
|
(int)PWINDOW->m_bIsFloating,
|
||||||
PWINDOW->m_iMonitorID,
|
PWINDOW->m_iMonitorID,
|
||||||
g_pXWaylandManager->getAppIDClass(PWINDOW).c_str(),
|
escapeJSONStrings(g_pXWaylandManager->getAppIDClass(PWINDOW)).c_str(),
|
||||||
g_pXWaylandManager->getTitle(PWINDOW).c_str(),
|
escapeJSONStrings(g_pXWaylandManager->getTitle(PWINDOW)).c_str(),
|
||||||
PWINDOW->getPID()
|
PWINDOW->getPID()
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -199,7 +199,7 @@ std::string layersRequest(HyprCtl::eHyprCtlOutputFormat format) {
|
||||||
R"#("%s": {
|
R"#("%s": {
|
||||||
"levels": {
|
"levels": {
|
||||||
)#",
|
)#",
|
||||||
mon->szName.c_str()
|
escapeJSONStrings(mon->szName).c_str()
|
||||||
);
|
);
|
||||||
|
|
||||||
int layerLevel = 0;
|
int layerLevel = 0;
|
||||||
|
@ -225,7 +225,7 @@ R"#( {
|
||||||
layer->geometry.y,
|
layer->geometry.y,
|
||||||
layer->geometry.width,
|
layer->geometry.width,
|
||||||
layer->geometry.height,
|
layer->geometry.height,
|
||||||
layer->szNamespace.c_str()
|
escapeJSONStrings(layer->szNamespace).c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +285,7 @@ R"#( {
|
||||||
"name": "%s"
|
"name": "%s"
|
||||||
},)#",
|
},)#",
|
||||||
&m,
|
&m,
|
||||||
m.mouse->name
|
escapeJSONStrings(m.mouse->name).c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,13 +308,13 @@ R"#( {
|
||||||
"active_keymap": "%s"
|
"active_keymap": "%s"
|
||||||
},)#",
|
},)#",
|
||||||
&k,
|
&k,
|
||||||
k.keyboard->name,
|
escapeJSONStrings(k.keyboard->name).c_str(),
|
||||||
k.currentRules.rules.c_str(),
|
escapeJSONStrings(k.currentRules.rules).c_str(),
|
||||||
k.currentRules.model.c_str(),
|
escapeJSONStrings(k.currentRules.model).c_str(),
|
||||||
k.currentRules.layout.c_str(),
|
escapeJSONStrings(k.currentRules.layout).c_str(),
|
||||||
k.currentRules.variant.c_str(),
|
escapeJSONStrings(k.currentRules.variant).c_str(),
|
||||||
k.currentRules.options.c_str(),
|
escapeJSONStrings(k.currentRules.options).c_str(),
|
||||||
KM
|
escapeJSONStrings(KM).c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ R"#( {
|
||||||
},)#",
|
},)#",
|
||||||
&d,
|
&d,
|
||||||
d.pTabletParent,
|
d.pTabletParent,
|
||||||
d.pTabletParent ? d.pTabletParent->wlrDevice ? d.pTabletParent->wlrDevice->name : "" : ""
|
escapeJSONStrings(d.pTabletParent ? d.pTabletParent->wlrDevice ? d.pTabletParent->wlrDevice->name : "" : "").c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ R"#( {
|
||||||
"name": "%s"
|
"name": "%s"
|
||||||
},)#",
|
},)#",
|
||||||
&d,
|
&d,
|
||||||
d.wlrDevice ? d.wlrDevice->name : ""
|
escapeJSONStrings(d.wlrDevice ? d.wlrDevice->name : "").c_str()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "../Compositor.hpp"
|
#include "../Compositor.hpp"
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
static const float transforms[][9] = {{
|
static const float transforms[][9] = {{
|
||||||
1.0f, 0.0f, 0.0f,
|
1.0f, 0.0f, 0.0f,
|
||||||
|
@ -113,6 +114,29 @@ std::string getFormat(const char *fmt, ...) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string escapeJSONStrings(const std::string& str) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
for (auto &c : str) {
|
||||||
|
switch (c) {
|
||||||
|
case '"': oss << "\\\""; break;
|
||||||
|
case '\\': oss << "\\\\"; break;
|
||||||
|
case '\b': oss << "\\b"; break;
|
||||||
|
case '\f': oss << "\\f"; break;
|
||||||
|
case '\n': oss << "\\n"; break;
|
||||||
|
case '\r': oss << "\\r"; break;
|
||||||
|
case '\t': oss << "\\t"; break;
|
||||||
|
default:
|
||||||
|
if ('\x00' <= c && c <= '\x1f') {
|
||||||
|
oss << "\\u"
|
||||||
|
<< std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(c);
|
||||||
|
} else {
|
||||||
|
oss << c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
void scaleBox(wlr_box* box, float scale) {
|
void scaleBox(wlr_box* box, float scale) {
|
||||||
box->width = std::round(box->width * scale);
|
box->width = std::round(box->width * scale);
|
||||||
box->height = std::round(box->height * scale);
|
box->height = std::round(box->height * scale);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
void addWLSignal(wl_signal*, wl_listener*, void* pOwner, std::string ownerString);
|
void addWLSignal(wl_signal*, wl_listener*, void* pOwner, std::string ownerString);
|
||||||
void wlr_signal_emit_safe(struct wl_signal *signal, void *data);
|
void wlr_signal_emit_safe(struct wl_signal *signal, void *data);
|
||||||
std::string getFormat(const char *fmt, ...); // Basically Debug::log to a string
|
std::string getFormat(const char *fmt, ...); // Basically Debug::log to a string
|
||||||
|
std::string escapeJSONStrings(const std::string& str);
|
||||||
void scaleBox(wlr_box*, float);
|
void scaleBox(wlr_box*, float);
|
||||||
std::string removeBeginEndSpacesTabs(std::string);
|
std::string removeBeginEndSpacesTabs(std::string);
|
||||||
bool isNumber(const std::string&, bool allowfloat = false);
|
bool isNumber(const std::string&, bool allowfloat = false);
|
||||||
|
|
|
@ -1067,27 +1067,56 @@ void CKeybindManager::circleNext(std::string arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CKeybindManager::focusWindow(std::string regexp) {
|
void CKeybindManager::focusWindow(std::string regexp) {
|
||||||
bool titleRegex = false;
|
eFocusWindowMode mode = MODE_CLASS_REGEX;
|
||||||
|
|
||||||
std::regex regexCheck(regexp);
|
std::regex regexCheck(regexp);
|
||||||
|
std::string matchCheck;
|
||||||
if (regexp.find("title:") == 0) {
|
if (regexp.find("title:") == 0) {
|
||||||
titleRegex = true;
|
mode = MODE_TITLE_REGEX;
|
||||||
regexCheck = std::regex(regexp.substr(6));
|
regexCheck = std::regex(regexp.substr(6));
|
||||||
}
|
}
|
||||||
|
else if (regexp.find("address:") == 0) {
|
||||||
|
mode = MODE_ADDRESS;
|
||||||
|
matchCheck = regexp.substr(8);
|
||||||
|
}
|
||||||
|
else if (regexp.find("pid:") == 0) {
|
||||||
|
mode = MODE_PID;
|
||||||
|
matchCheck = regexp.substr(4);
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& w : g_pCompositor->m_vWindows) {
|
for (auto& w : g_pCompositor->m_vWindows) {
|
||||||
if (!w->m_bIsMapped || w->m_bHidden)
|
if (!w->m_bIsMapped || w->m_bHidden)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (titleRegex) {
|
switch (mode) {
|
||||||
|
case MODE_CLASS_REGEX: {
|
||||||
|
const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get());
|
||||||
|
if (!std::regex_search(g_pXWaylandManager->getAppIDClass(w.get()), regexCheck))
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MODE_TITLE_REGEX: {
|
||||||
const auto windowTitle = g_pXWaylandManager->getTitle(w.get());
|
const auto windowTitle = g_pXWaylandManager->getTitle(w.get());
|
||||||
if (!std::regex_search(windowTitle, regexCheck))
|
if (!std::regex_search(windowTitle, regexCheck))
|
||||||
continue;
|
continue;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else {
|
case MODE_ADDRESS: {
|
||||||
const auto windowClass = g_pXWaylandManager->getAppIDClass(w.get());
|
std::string addr = getFormat("0x%x", w.get());
|
||||||
if (!std::regex_search(windowClass, regexCheck))
|
if (matchCheck != addr)
|
||||||
continue;
|
continue;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case MODE_PID: {
|
||||||
|
std::string pid = getFormat("%d", w->getPID());
|
||||||
|
if (matchCheck != pid)
|
||||||
|
continue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Debug::log(LOG, "Focusing to window name: %s", w->m_szTitle.c_str());
|
Debug::log(LOG, "Focusing to window name: %s", w->m_szTitle.c_str());
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,13 @@ private:
|
||||||
static void setSubmap(std::string);
|
static void setSubmap(std::string);
|
||||||
|
|
||||||
friend class CCompositor;
|
friend class CCompositor;
|
||||||
|
|
||||||
|
enum eFocusWindowMode {
|
||||||
|
MODE_CLASS_REGEX = 0,
|
||||||
|
MODE_TITLE_REGEX,
|
||||||
|
MODE_ADDRESS,
|
||||||
|
MODE_PID
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::unique_ptr<CKeybindManager> g_pKeybindManager;
|
inline std::unique_ptr<CKeybindManager> g_pKeybindManager;
|
Loading…
Reference in a new issue