Skip to content

Commit ed8ff3b

Browse files
committed
nixos: Prevent xochitl from running concurrently
1 parent 680f317 commit ed8ff3b

4 files changed

Lines changed: 23 additions & 12 deletions

File tree

apps/rocket/Hideable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class HideableRenderObject
6565
auto result = this->child->draw(canvas, { 0, 0 });
6666
if (doRefresh) {
6767
doRefresh = false;
68-
result.waveform = rmlib::fb::Waveform::GC16;
69-
result.flags = rmlib::fb::UpdateFlags::FullRefresh;
68+
result.waveform = rmlib::fb::Waveform::GC16Fast;
69+
// result.flags = rmlib::fb::UpdateFlags::FullRefresh;
7070
}
7171

7272
return result;

apps/rocket/Launcher.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ LauncherState::tick() const {
221221

222222
void
223223
LauncherState::toggle(rmlib::AppContext& context) {
224+
background.reset();
224225
if (visible) {
225226
bool shouldStartTimer = sleepCountdown <= 0;
226227
stopTimer();
@@ -237,8 +238,6 @@ LauncherState::show() {
237238
return;
238239
}
239240

240-
background.reset();
241-
242241
if (auto err = getWidget().ctlClient.switchTo(getpid()); !err) {
243242
std::cerr << "Error switching: " << to_string(err.error()) << "\n";
244243
}
@@ -270,7 +269,7 @@ LauncherState::switchApp(pid_t pid) {
270269
}
271270

272271
void
273-
LauncherState::launch(App& app) {
272+
LauncherState::launch(rmlib::AppContext& ctx, App& app) {
274273
stopTimer();
275274

276275
if (!app.launch()) {
@@ -280,6 +279,8 @@ LauncherState::launch(App& app) {
280279

281280
if (auto icon = app.icon(); icon.has_value()) {
282281
background = *icon;
282+
backgroundTimer = ctx.addTimer(std::chrono::seconds(3),
283+
[this] { modify().background.reset(); });
283284
}
284285
}
285286

@@ -295,9 +296,9 @@ LauncherState::onSignal() {
295296
if (*sigOrErr == SIGUSR1) {
296297
stopTimer();
297298
visible = false;
299+
background.reset();
298300
} else if (*sigOrErr == SIGCONT) {
299301
visible = true;
300-
background.reset();
301302

302303
readApps();
303304
requestClients();

apps/rocket/Launcher.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ class LauncherState : public rmlib::StateBase<LauncherWidget> {
102102
return Wrap(widgets);
103103
}
104104

105-
auto appList() const {
105+
auto appList(rmlib::AppContext& ctx) const {
106106
using namespace rmlib;
107107

108108
std::vector<AppWidget> widgets;
109109
for (const auto& app : apps) {
110110
if (!isRunning(app.getLaunchPid())) {
111-
widgets.emplace_back(app, [this, &app] {
111+
widgets.emplace_back(app, [this, &app, &ctx] {
112112
setState(
113-
[&app](auto& self) { self.launch(*const_cast<App*>(&app)); });
113+
[&](auto& self) { self.launch(ctx, *const_cast<App*>(&app)); });
114114
});
115115
}
116116
}
@@ -120,7 +120,7 @@ class LauncherState : public rmlib::StateBase<LauncherWidget> {
120120
auto launcher(rmlib::AppContext& context) const {
121121
using namespace rmlib;
122122

123-
return Cleared(Column(header(context), runningApps(), appList()));
123+
return Cleared(Column(header(context), runningApps(), appList(context)));
124124
}
125125

126126
auto build(rmlib::AppContext& context,
@@ -165,7 +165,7 @@ class LauncherState : public rmlib::StateBase<LauncherWidget> {
165165
void hide(rmlib::AppContext* context);
166166
void toggle(rmlib::AppContext& context);
167167

168-
void launch(App& app);
168+
void launch(rmlib::AppContext& ctx, App& app);
169169
void switchApp(pid_t pid);
170170

171171
void onSignal();
@@ -185,6 +185,7 @@ class LauncherState : public rmlib::StateBase<LauncherWidget> {
185185

186186
rmlib::TimerHandle sleepTimer;
187187
rmlib::TimerHandle inactivityTimer;
188+
rmlib::TimerHandle backgroundTimer;
188189

189190
rmlib::Rotation rotation = rmlib::Rotation::None;
190191
std::optional<rmlib::Canvas> background;

nix/modules/xochitl.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ let
1010
};
1111
xochitl = pkgs.writeShellApplication {
1212
name = "xochitl";
13-
runtimeInputs = [ pkgs.systemd ];
13+
runtimeInputs = with pkgs; [
14+
systemd
15+
util-linux
16+
];
1417
text = ''
18+
exec {fd}>"''${XDG_RUNTIME_DIR:-/run}/xochitl.lock"
19+
if ! flock -n -x $fd; then
20+
echo "Only one xochitl supported!"
21+
exit 1
22+
fi
23+
1524
ctlCmd="systemctl"
1625
if [ "$EUID" -ne "0" ]; then
1726
ctlCmd="systemctl --user"

0 commit comments

Comments
 (0)