Skip to content

Commit 09891aa

Browse files
committed
Replaced all instances of battery with script.
1 parent cbba048 commit 09891aa

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# swaylock-effects-battery
1+
# swaylock-effects-script
22

3-
Swaylock-effects-battery is a fork of [swaylock-effects](https://github.com/jirutka/swaylock-effects)
4-
which adds a battery percentage display feature.
3+
Swaylock-effects-script is a fork of [swaylock-effects](https://github.com/jirutka/swaylock-effects)
4+
which adds a script output display feature.
55

66
Swaylock-effects is a fork of [swaylock](https://github.com/swaywm/swaylock)
77
which adds built-in screenshots and image manipulation effects like blurring.
@@ -18,7 +18,7 @@ which is no longer maintained.
1818

1919
swaylock \
2020
--screenshots \
21-
--battery ~/path_to_script \
21+
--script ~/path_to_script \
2222
--clock \
2323
--indicator \
2424
--indicator-radius 100 \
@@ -37,7 +37,7 @@ which is no longer maintained.
3737

3838
The main new features compared to upstream swaylock are:
3939

40-
* `--battery` to display the battery percentage
40+
* `--script` to display the script output
4141
* `--screenshots` to use screenshots instead of an image on disk or a color
4242
* `--clock` to show date/time in the indicator
4343
* Use `--indicator` to make the indicator always active

include/swaylock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ struct swaylock_args {
8282
bool password_grace_no_mouse;
8383
bool password_grace_no_touch;
8484

85-
bool display_battery;
86-
char *battery_str;
87-
char *battery_path;
85+
bool display_script;
86+
char *script_str;
87+
char *script_path;
8888

8989
char *text_cleared;
9090
char *text_caps_lock;

main.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "wlr-screencopy-unstable-v1-client-protocol.h"
3131
#include "ext-session-lock-v1-client-protocol.h"
3232

33-
#define MAX_BATTERY_STR_LEN 5
3433
#define MAX_OUTPUT_SIZE 1024
3534

3635
static struct swaylock_state state;
@@ -39,12 +38,12 @@ void update_script() {
3938
FILE *pipe;
4039
char path[1035];
4140
char output[MAX_OUTPUT_SIZE];
42-
char *battery_str = (char *)malloc((MAX_OUTPUT_SIZE + 1) * sizeof(char));
41+
char *script_str = (char *)malloc((MAX_OUTPUT_SIZE + 1) * sizeof(char));
4342

44-
pipe = popen(state.args.battery_path, "r");
43+
pipe = popen(state.args.script_path, "r");
4544

4645
if (pipe == NULL) {
47-
fprintf(stderr, "Failed to run battery script.\n");
46+
fprintf(stderr, "Failed to run script.\n");
4847
return;
4948
}
5049

@@ -57,9 +56,9 @@ void update_script() {
5756

5857
pclose(pipe);
5958

60-
snprintf(battery_str, MAX_OUTPUT_SIZE, "%s", output);
59+
snprintf(script_str, MAX_OUTPUT_SIZE, "%s", output);
6160

62-
state.args.battery_str = battery_str;
61+
state.args.script_str = script_str;
6362
}
6463

6564
// returns a positive integer in milliseconds
@@ -430,7 +429,7 @@ static const struct wl_callback_listener surface_frame_listener;
430429
static void surface_frame_handle_done(void *data, struct wl_callback *callback,
431430
uint32_t time) {
432431

433-
if (state.args.display_battery) {
432+
if (state.args.display_script) {
434433
update_script();
435434
};
436435

@@ -1012,7 +1011,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
10121011
LO_TIME_EFFECTS,
10131012
LO_INDICATOR,
10141013
LO_CLOCK,
1015-
LO_BATTERY,
1014+
LO_SCRIPT,
10161015
LO_TIMESTR,
10171016
LO_DATESTR,
10181017
LO_FADE_IN,
@@ -1093,7 +1092,7 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
10931092
{"time-effects", no_argument, NULL, LO_TIME_EFFECTS},
10941093
{"indicator", no_argument, NULL, LO_INDICATOR},
10951094
{"clock", no_argument, NULL, LO_CLOCK},
1096-
{"battery", required_argument, NULL, LO_BATTERY},
1095+
{"script", required_argument, NULL, LO_SCRIPT},
10971096
{"timestr", required_argument, NULL, LO_TIMESTR},
10981097
{"datestr", required_argument, NULL, LO_DATESTR},
10991098
{"fade-in", required_argument, NULL, LO_FADE_IN},
@@ -1153,8 +1152,8 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
11531152
"Disable the unlock indicator.\n"
11541153
" --indicator "
11551154
"Always show the indicator.\n"
1156-
" --battery "
1157-
"Show the battery percentage.\n"
1155+
" --script "
1156+
"Show the script output.\n"
11581157
" --clock "
11591158
"Show time and date.\n"
11601159
" --timestr <format> "
@@ -1660,10 +1659,10 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
16601659
state->args.clock = true;
16611660
}
16621661
break;
1663-
case LO_BATTERY:
1662+
case LO_SCRIPT:
16641663
if (state) {
1665-
state->args.battery_path = strdup(optarg);
1666-
state->args.display_battery = true;
1664+
state->args.script_path = strdup(optarg);
1665+
state->args.display_script = true;
16671666
}
16681667
update_script();
16691668
break;
@@ -1894,9 +1893,9 @@ int main(int argc, char **argv) {
18941893
.allow_fade = true,
18951894
.password_grace_period = 0,
18961895

1897-
.display_battery = false,
1898-
.battery_str = NULL,
1899-
.battery_path = NULL,
1896+
.display_script = false,
1897+
.script_str = NULL,
1898+
.script_path = NULL,
19001899

19011900
.text_cleared = strdup("Cleared"),
19021901
.text_caps_lock = strdup("Caps Lock"),

render.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ static void subtext(struct swaylock_surface *surface, char **tstr, char **dstr,
6868
*dstr = NULL;
6969
}
7070

71-
if (surface->state->args.display_battery) {
72-
// Write battery percentage
73-
snprintf(bbuf, sizeof(bbuf), "%s", surface->state->args.battery_str);
71+
if (surface->state->args.display_script) {
72+
// Write script output
73+
snprintf(bbuf, sizeof(bbuf), "%s", surface->state->args.script_str);
7474
*bstr = bbuf;
7575
} else {
7676
*bstr = NULL;
@@ -300,7 +300,7 @@ void render_frame(struct swaylock_surface *surface) {
300300
snprintf(attempts, sizeof(attempts), "%d", state->failed_attempts);
301301
text = attempts;
302302
}
303-
} else if (state->args.clock || state->args.display_battery) {
303+
} else if (state->args.clock || state->args.display_script) {
304304
subtext(surface, &text_l1, &text_l2, &text_l3);
305305
}
306306

@@ -320,7 +320,7 @@ void render_frame(struct swaylock_surface *surface) {
320320
}
321321
break;
322322
default:
323-
if (state->args.clock || state->args.display_battery)
323+
if (state->args.clock || state->args.display_script)
324324
subtext(surface, &text_l1, &text_l2, &text_l3);
325325
break;
326326
}

0 commit comments

Comments
 (0)