Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

145 changes: 145 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/swaylock-effects.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/swaylock-effects2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"ext-session-lock-v1-client-protocol.h": "c"
}
}
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# swaylock-effects
# swaylock-effects-script

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

Swaylock-effects is a fork of [swaylock](https://github.com/swaywm/swaylock)
which adds built-in screenshots and image manipulation effects like blurring.
It's inspired by [i3lock-color](https://github.com/PandorasFox/i3lock-color),
although the feature sets aren't perfectly overlapping.

This repository ([jirutka/swaylock-effects](https://github.com/jirutka/swaylock-effects))
This repository ([sidharthmrao/swaylock-effects-script](https://github.com/sidharthmrao/swaylock-effects-script))
is a fork of ([jirutka/swaylock-effects](https://github.com/jirutka/swaylock-effects)) which
is a fork of [mortie/swaylock-effects](https://github.com/mortie/swaylock-effects)
which is no longer maintained.

Expand All @@ -15,6 +19,7 @@ which is no longer maintained.

swaylock \
--screenshots \
--script `path_to_script` \
--clock \
--indicator \
--indicator-radius 100 \
Expand All @@ -33,6 +38,7 @@ which is no longer maintained.

The main new features compared to upstream swaylock are:

* `--script` to display the script output
* `--screenshots` to use screenshots instead of an image on disk or a color
* `--clock` to show date/time in the indicator
* Use `--indicator` to make the indicator always active
Expand Down Expand Up @@ -130,6 +136,10 @@ Run these commands:
ninja -C build
sudo ninja -C build install

On systems with PAM, copy pam/swaylock to /etc/pam.d/swaylock

sudo cp pam/swaylock /etc/pam.d/swaylock

On systems without PAM, you need to suid the swaylock binary:

sudo chmod a+s /usr/local/bin/swaylock
Expand Down
4 changes: 4 additions & 0 deletions include/swaylock.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ struct swaylock_args {
bool password_grace_no_mouse;
bool password_grace_no_touch;

bool display_script;
char *script_str;
char *script_path;

char *text_cleared;
char *text_caps_lock;
char *text_verifying;
Expand Down
57 changes: 53 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

man snprintf - The functions snprintf() and vsnprintf() write at most size bytes (including the terminating null byte ('\0')) to str.

Comment on lines +39 to +41

Choose a reason for hiding this comment

The 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 MAX_OUTPUT_SIZE bytes to the user, so why not just fgets that last line into script_str? do we need to be doing all that?


pipe = popen(state.args.script_path, "r");

if (pipe == NULL) {
fprintf(stderr, "Failed to run script.\n");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this project has a swaylock_log_errno defined somewhere, and popen sets errno - does the file not exist? are its permissions insufficient? etc

return;
}

memset(output, 0, sizeof(output));

while (fgets(path, sizeof(path), pipe) != NULL) {
Copy link

@ngruychev ngruychev May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whole loop might not be needed as sizeof(path) > sizeof(output) - what are we trying to do here?

path[strcspn(path, "\r\n")] = '\0';
strcat(output, path);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no guarantee that sizeof(output) >= strlen(output) + strlen(path) + 1

}

pclose(pipe);

snprintf(script_str, MAX_OUTPUT_SIZE, "%s", output);

state.args.script_str = script_str;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is a previous script_str freed?

}

// returns a positive integer in milliseconds
static uint32_t parse_seconds(const char *seconds) {
char *endptr;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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> "
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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"),
Expand Down
Loading