-
-
Notifications
You must be signed in to change notification settings - Fork 24
Add an option to display the output of a script. (Originally battery percentage). #65
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
base: master
Are you sure you want to change the base?
Changes from all commits
927a9e5
9ce590e
e65fff2
7c973b7
eef9f19
ade1241
4fb870a
c9eee26
c7e6ffd
1f170bc
fa2a2c5
9a40cbb
3ed8fbe
626176e
cbabee5
f96b66f
cbba048
09891aa
86381d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "files.associations": { | ||
| "ext-session-lock-v1-client-protocol.h": "c" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,37 @@ | |
| #include "wlr-screencopy-unstable-v1-client-protocol.h" | ||
| #include "ext-session-lock-v1-client-protocol.h" | ||
|
|
||
| #define MAX_OUTPUT_SIZE 1024 | ||
|
|
||
| static struct swaylock_state state; | ||
|
|
||
| void update_script() { | ||
| FILE *pipe; | ||
| char path[1035]; | ||
| char output[MAX_OUTPUT_SIZE]; | ||
| char *script_str = (char *)malloc((MAX_OUTPUT_SIZE + 1) * sizeof(char)); | ||
|
Comment on lines
+39
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at the end of the day we're only showing a single line (I'm assuming the intent is to read only one line of the script's output) of |
||
|
|
||
| pipe = popen(state.args.script_path, "r"); | ||
|
|
||
| if (pipe == NULL) { | ||
| fprintf(stderr, "Failed to run script.\n"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this project has a |
||
| return; | ||
| } | ||
|
|
||
| memset(output, 0, sizeof(output)); | ||
|
|
||
| while (fgets(path, sizeof(path), pipe) != NULL) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whole loop might not be needed as |
||
| path[strcspn(path, "\r\n")] = '\0'; | ||
| strcat(output, path); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no guarantee that |
||
| } | ||
|
|
||
| pclose(pipe); | ||
|
|
||
| snprintf(script_str, MAX_OUTPUT_SIZE, "%s", output); | ||
|
|
||
| state.args.script_str = script_str; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is a previous |
||
| } | ||
|
|
||
| // returns a positive integer in milliseconds | ||
| static uint32_t parse_seconds(const char *seconds) { | ||
| char *endptr; | ||
|
|
@@ -397,6 +428,11 @@ static const struct wl_callback_listener surface_frame_listener; | |
|
|
||
| static void surface_frame_handle_done(void *data, struct wl_callback *callback, | ||
| uint32_t time) { | ||
|
|
||
| if (state.args.display_script) { | ||
| update_script(); | ||
| }; | ||
|
|
||
| struct swaylock_surface *surface = data; | ||
|
|
||
| wl_callback_destroy(callback); | ||
|
|
@@ -975,6 +1011,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, | |
| LO_TIME_EFFECTS, | ||
| LO_INDICATOR, | ||
| LO_CLOCK, | ||
| LO_SCRIPT, | ||
| LO_TIMESTR, | ||
| LO_DATESTR, | ||
| LO_FADE_IN, | ||
|
|
@@ -1055,6 +1092,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, | |
| {"time-effects", no_argument, NULL, LO_TIME_EFFECTS}, | ||
| {"indicator", no_argument, NULL, LO_INDICATOR}, | ||
| {"clock", no_argument, NULL, LO_CLOCK}, | ||
| {"script", required_argument, NULL, LO_SCRIPT}, | ||
| {"timestr", required_argument, NULL, LO_TIMESTR}, | ||
| {"datestr", required_argument, NULL, LO_DATESTR}, | ||
| {"fade-in", required_argument, NULL, LO_FADE_IN}, | ||
|
|
@@ -1114,6 +1152,8 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, | |
| "Disable the unlock indicator.\n" | ||
| " --indicator " | ||
| "Always show the indicator.\n" | ||
| " --script " | ||
| "Show the script output.\n" | ||
| " --clock " | ||
| "Show time and date.\n" | ||
| " --timestr <format> " | ||
|
|
@@ -1619,6 +1659,13 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, | |
| state->args.clock = true; | ||
| } | ||
| break; | ||
| case LO_SCRIPT: | ||
| if (state) { | ||
| state->args.script_path = strdup(optarg); | ||
| state->args.display_script = true; | ||
| } | ||
| update_script(); | ||
| break; | ||
| case LO_TIMESTR: | ||
| if (state) { | ||
| free(state->args.timestr); | ||
|
|
@@ -1741,8 +1788,6 @@ static int load_config(char *path, struct swaylock_state *state, | |
| return 0; | ||
| } | ||
|
|
||
| static struct swaylock_state state; | ||
|
|
||
| static void display_in(int fd, short mask, void *data) { | ||
| if (wl_display_dispatch(state.display) == -1) { | ||
| state.run_display = false; | ||
|
|
@@ -1823,8 +1868,8 @@ int main(int argc, char **argv) { | |
| .mode = BACKGROUND_MODE_FILL, | ||
| .font = strdup("sans-serif"), | ||
| .font_size = 0, | ||
| .radius = 75, | ||
| .thickness = 10, | ||
| .radius = 100, | ||
| .thickness = 9, | ||
| .indicator_x_position = 0, | ||
| .indicator_y_position = 0, | ||
| .override_indicator_x_position = false, | ||
|
|
@@ -1848,6 +1893,10 @@ int main(int argc, char **argv) { | |
| .allow_fade = true, | ||
| .password_grace_period = 0, | ||
|
|
||
| .display_script = false, | ||
| .script_str = NULL, | ||
| .script_path = NULL, | ||
|
|
||
| .text_cleared = strdup("Cleared"), | ||
| .text_caps_lock = strdup("Caps Lock"), | ||
| .text_verifying = strdup("Verifying"), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
man snprintf- The functionssnprintf()andvsnprintf()write at mostsizebytes (including the terminating null byte ('\0')) tostr.