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

API feature #235

Closed
wants to merge 9 commits into from
Closed

API feature #235

wants to merge 9 commits into from

Conversation

JezerM
Copy link

@JezerM JezerM commented Aug 26, 2021

Closes #234

Description

  • Adds the ability to update i3lock through a piping API.
  • Enable this with --api-enable flag
  • It is insecure. Send --no-verify and screen is unlocked. (Fixed)

Screenshots/screencaps

Video.25-8-21.21.01.05.mov

Release notes

Notes: Added API feature

Copy link
Collaborator

@Rio6 Rio6 left a comment

Choose a reason for hiding this comment

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

Do we really need to include word expansion into i3lock-color? I feel that should be the job for the scripts writing the the fifo and not here.

pthread_t api_thread;
// this enables api access to update i3lock
bool api_enabled = false;
char *api_fifo_path = "/tmp/i3lock-api";
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can probably utilize XDG_RUNTIME_DIR environment variable before falling back to a default (in addition to specifying a path from command line).

i3lock.c Outdated Show resolved Hide resolved
i3lock.c Outdated Show resolved Hide resolved
i3lock.c Outdated Show resolved Hide resolved
@@ -1437,19 +1489,10 @@ static void load_slideshow_images(const char *path, char *image_raw_format) {
closedir(d);
}

int main(int argc, char *argv[]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might make merging from upstream harder, although I don't have a better way for now

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Raymo111 I think you're usually the one merging from upstream, what do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah this would probably pose issues down the line, can we make this work without shrinking main by that much?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it's possible to rearrange the code a bit to reduce the diff size. Seems like most of the diff are in this file?

@JezerM
Copy link
Author

JezerM commented Aug 30, 2021

Changes

  • Using custom parser, instead of wordexp
  • Arguments are now limited
  • No big changes to main
  • There's thread locking on redraw_screen to avoid unnecessary and problematic redraws at the same time.
  • Images working! (kinda)

Considerations

  • Image updates work, but not as expected. Could lead to performance issues and a high chance of crashing. Better to use i3lock-color slideshow feature.
  • Multiple updates at short intervals might not be seen: set --refresh-rate to a lower value.
Video.29-8-21.23.29.59.mov

api.c Outdated Show resolved Hide resolved
api.c Outdated Show resolved Hide resolved
api.h Outdated Show resolved Hide resolved
api.c Outdated Show resolved Hide resolved
api.c Outdated Show resolved Hide resolved
api.c Outdated Show resolved Hide resolved
i3lock.c Outdated Show resolved Hide resolved
i3lock.c Show resolved Hide resolved
api.c Outdated Show resolved Hide resolved
api.c Outdated Show resolved Hide resolved
@JezerM
Copy link
Author

JezerM commented Sep 14, 2021

Changes

  • parse_args kind of refactored.
  • getopt_long moved from main to update_arguments, which can be accessed by listen_api
  • --enable-api flag renamed to --api-enable
    • Added --api-path flag to change the api fifo path
    • Added --api-redraw flag to force redraw when an api message is received
  • Added support for this kind of program
  • Changing image with --image flag through api does not crash as before.

@JezerM JezerM mentioned this pull request Sep 16, 2021
2 tasks
@JezerM JezerM marked this pull request as ready for review September 19, 2021 19:15
@JezerM
Copy link
Author

JezerM commented Jan 10, 2022

Setting images through API works without any issue (no crashes):

Upload.from.GitHub.for.iOS.MOV

However, big files at low intervals can slow i3lock if your graphics are slow:

Upload.from.GitHub.for.iOS.MOV

Copy link
Collaborator

@Rio6 Rio6 left a comment

Choose a reason for hiding this comment

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

Besides the comments in code, I think it looks good.

I'm personally not a big fan of parse_args related code (maybe something like wordexp(3) can be used instead). But it's probably fine for now.

api.c Outdated Show resolved Hide resolved
text[i] = c;
i++;
}
text[i] = '\0';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the size of text is always larger than i here?

Copy link
Author

@JezerM JezerM Jan 12, 2022

Choose a reason for hiding this comment

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

Yep, as we increase the memory of text by 2 if the size of text is lower or equal than i. It should always be enough memory to insert the NULL character.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about the case when in the beginning of the loop i == size - 1. The loop doesn't get extended and i++ gets executed. If the loop exits at this iteration, i == size and writing to text[size] is out of bounds.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, it would be out of bounds. if (size <= i + 1) { /* reallocate */ } should do the thing.

api.c Outdated Show resolved Hide resolved
api.c Outdated Show resolved Hide resolved
i3lock.c Outdated Show resolved Hide resolved
i3lock.h Show resolved Hide resolved
@@ -1437,19 +1489,10 @@ static void load_slideshow_images(const char *path, char *image_raw_format) {
closedir(d);
}

int main(int argc, char *argv[]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it's possible to rearrange the code a bit to reduce the diff size. Seems like most of the diff are in this file?

@JezerM
Copy link
Author

JezerM commented Jan 12, 2022

But wordexp performs word expansion, something that i3lock shouldn't do, as you stated before.

I don't think we need wordexp here though, just need a simple parser to parse escaped space and quotes.

@Rio6
Copy link
Collaborator

Rio6 commented Jan 12, 2022

But wordexp performs word expansion, something that i3lock shouldn't do, as you stated before.

I don't think we need wordexp here though, just need a simple parser to parse escaped space and quotes.

Sorry I'm incinsistent, ignore me on this whole parsing part. I'm not sure which way I like either :P.

I looked at my old comment and I agree with my previous self, wordexp does too much. I completely forgot what it does other than the function name. It's good right now.

@Naheel-Azawy
Copy link

Hi, this looks pretty good. Why it hasn't been merged yet?

@JezerM
Copy link
Author

JezerM commented Feb 18, 2022

Hi, this looks pretty good. Why it hasn't been merged yet?

This feature is huge, and it does some big changes inside the main function, which could make it difficult to pull from i3lock.

Besides, even if this feature looks cool, it's mostly unnecessary. It's an extra that does a lot~

@Raymo111
Copy link
Owner

Yeah what @JezerM said basically.

Jez I think I'll close this PR for now, and if we really need it someday we can reconsider it. Thanks for putting in all the effort still, it means a lot. If you'd like you can maintain an API branch/fork and keep it up to date with master so that if someone wants the feature they can use your fork?

@JezerM
Copy link
Author

JezerM commented Feb 18, 2022

Yeah, I could~

@Raymo111 Raymo111 closed this Feb 18, 2022
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

Successfully merging this pull request may close these issues.

Support displaying custom dynamic text
4 participants