Skip to content

Commit

Permalink
IPC: new event for marks
Browse files Browse the repository at this point in the history
  • Loading branch information
dawsers committed Dec 20, 2024
1 parent 5144971 commit 8be0909
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ You can use any string name for a mark, for example in scripts. But they are
also very convenient to use with regular key bindings by simply using a letter
as the name. Again, see the example configuration.

*hyprscroller* generates IPC signals for mark events, and in this
README there is an example implementation for [ags](https://github.com/Aylur/ags)
to use those signals to display information on your desktop bar.


## Pinning a Column

Expand Down Expand Up @@ -432,6 +436,7 @@ events that trigger a message:
| `scroller expelwindow` | expelling a window | |
| `scroller overview` | toggling overview mode | `0/1` |
| `scroller mode` | changing mode | `row/column` |
| `scroller mark` | current window marked? | `0/1`, `mark_name` |
| `scroller trail` | current trail information | `number`, `size` |
| `scroller trailmark` | current window trailmark? | `0/1` |

Expand Down Expand Up @@ -484,6 +489,10 @@ export function Scroller() {
class_name: "scroller-overview",
label: ''
});
const mark_label = Widget.Label({
class_name: "scroller-mark",
label: ''
});
const trailmark_label = Widget.Label({
class_name: "scroller-trailmark",
label: ''
Expand All @@ -497,6 +506,7 @@ export function Scroller() {
children: [
mode_label,
overview_label,
mark_label,
trail_label,
trailmark_label,
],
Expand Down Expand Up @@ -530,6 +540,16 @@ export function Scroller() {
} else {
trailmark_label.label = "";
}

} else if (text.startsWith("scroller>>mark,")) {
const mark = text.substring(15).trim().split(",");
const enabled = mark[0].trim();
if (enabled == "1") {
const name = mark[1].trim();
mark_label.label = "🔖" + " " + name;
} else {
mark_label.label = "";
}
}
}
function connection() {
Expand Down Expand Up @@ -585,6 +605,11 @@ and a simple `style.css`
padding-bottom: 10px;
padding-right: 10px;
}
.scroller-mark {
padding-top: 10px;
padding-bottom: 10px;
padding-right: 10px;
}
.scroller-trailmark {
padding-top: 10px;
padding-bottom: 10px;
Expand Down
17 changes: 17 additions & 0 deletions src/scroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,24 @@ class Marks {
~Marks() { reset(); }
void reset() {
marks.clear();
post_mark_event(nullptr);
}
// Add a mark with name for window, overwriting any existing one with that name
void add(PHLWINDOW window, const std::string &name) {
const auto mark = marks.find(name);
if (mark != marks.end()) {
mark->second = window;
post_mark_event(window);
return;
}
marks[name] = window;
post_mark_event(window);
}
void del(const std::string &name) {
const auto mark = marks.find(name);
if (mark != marks.end()) {
if (g_pCompositor->m_pLastWindow == mark->second)
post_mark_event(nullptr);
marks.erase(mark);
}
}
Expand All @@ -65,6 +70,17 @@ class Marks {
return nullptr;
}

void post_mark_event(PHLWINDOW window) {
bool marked = false;
for(auto it = marks.begin(); it != marks.end(); it++) {
if (it->second.lock() == window) {
g_pEventManager->postEvent(SHyprIPCEvent{"scroller", std::format("mark, 1, {}", it->first)});
return;
}
}
g_pEventManager->postEvent(SHyprIPCEvent{"scroller", "mark, 0, "});
}

private:
std::unordered_map<std::string, PHLWINDOWREF> marks;
};
Expand Down Expand Up @@ -658,6 +674,7 @@ void ScrollerLayout::onEnable() {
activeWindowHookCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "activeWindow", [&](void* /* self */, SCallbackInfo& /* info */, std::any param) {
auto window = std::any_cast<PHLWINDOW>(param);
trails->post_trailmark_event(window);
marks.post_mark_event(window);
});

swipeBeginHookCallback = HyprlandAPI::registerCallbackDynamic(PHANDLE, "swipeBegin", [&](void* /* self */, SCallbackInfo& /* info */, std::any param) {
Expand Down

0 comments on commit 8be0909

Please sign in to comment.