Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -no-input option to not listen to stdin #37

Open
DhruvaSambrani opened this issue Jan 19, 2024 · 5 comments
Open

Add -no-input option to not listen to stdin #37

DhruvaSambrani opened this issue Jan 19, 2024 · 5 comments

Comments

@DhruvaSambrani
Copy link
Contributor

To run dwlb with -no-ipc in the background fails since dwlb is listening to stdin, which puts the application in a suspend state

image

Add this option to not listen to stdin. so dwlb can be bg'd

@DhruvaSambrani
Copy link
Contributor Author

DhruvaSambrani commented Jan 20, 2024

This could be a valid patch. It doesn't include the option to turn it off using command line yet, but it is trivial to add if necessary.

diff --git a/config.def.h b/config.def.h
index 017258e..1e974cf 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,5 +1,7 @@
 // use ipc functionality
 static bool ipc = false;
+// nostdin
+static bool nostdin = false;
 // initially hide all bars
 static bool hidden = false;
 // initially draw all bars at the bottom
diff --git a/dwlb.c b/dwlb.c
index 40a79f2..c943ca4 100644
--- a/dwlb.c
+++ b/dwlb.c
@@ -1552,7 +1552,7 @@ event_loop(void)
 				break;
 		if (FD_ISSET(sock_fd, &rfds))
 			read_socket();
-		if (!ipc && FD_ISSET(STDIN_FILENO, &rfds))
+		if (!ipc && !nostdin && FD_ISSET(STDIN_FILENO, &rfds))
 			read_stdin();
 		
 		Bar *bar;

I can add this feature and send a PR if you want to add this.

@DhruvaSambrani
Copy link
Contributor Author

Ok, so the above patch does fix the issue, but now the loop constantly runs, increasing cpu usage like crazy. I don't quite understand yet why calling read_stdin() prevents the loop from constantly while still allowing read_ipc to trigger without an issue.

@DhruvaSambrani
Copy link
Contributor Author

Workaround:
sleep infinity | dwlb -no-ipc

Why it works: dwlb's stdin is now sleep's stdout which does not close even when sent to bg. Since sleep inifinity never writes to stdout, it is as if there is an open stdin but no text in there.

@kolunmi
Copy link
Owner

kolunmi commented Feb 11, 2024

Hello! Go ahead and make a pull request and I will merge it

@DhruvaSambrani
Copy link
Contributor Author

Like I mentioned before, the "fix" makes the mainloop jump to the next iteration immediately, causing 100% usage of the core that is running dwlb. I am not sure how read_stdin slows the loop, but it doesn't make my laptop a stove!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants