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

Dynamically update the greeter text #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
28 changes: 27 additions & 1 deletion i3lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ int internal_line_source = 0;
float refresh_rate = 1.0;

bool show_clock = false;
bool update_greeter = false;
bool slideshow_enabled = false;
bool always_show_clock = false;
bool show_indicator = false;
Expand Down Expand Up @@ -198,6 +199,7 @@ char* lock_failed_text = "lock failed!";
int keylayout_mode = -1;
char* layout_text = NULL;
char* greeter_text = "";
char* greeter_cmd = "";

/* opts for blurring */
bool blur = false;
Expand Down Expand Up @@ -1603,6 +1605,7 @@ int main(int argc, char *argv[]) {
{"indicator", no_argument, NULL, 401},
{"radius", required_argument, NULL, 402},
{"ring-width", required_argument, NULL, 403},
{"greeter-cmd", required_argument, NULL, 404},

// alignment
{"time-align", required_argument, NULL, 500},
Expand Down Expand Up @@ -1940,6 +1943,10 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "ring-width must be a positive float; ignoring...\n");
ring_width = 7.0;
}
break;
case 404:
update_greeter = true;
greeter_cmd = optarg;
break;

// Alignment stuff
Expand Down Expand Up @@ -2014,6 +2021,9 @@ int main(int argc, char *argv[]) {
lock_failed_text = optarg;
break;
case 518:
if (greeter_cmd) {
errx(EXIT_FAILURE, "i3lock-color: Options greeter-text and greeter-cmd conflict.");
}
greeter_text = optarg;
break;
case 519:
Expand Down Expand Up @@ -2626,7 +2636,7 @@ int main(int argc, char *argv[]) {
* file descriptor becomes readable). */
ev_invoke(main_loop, xcb_check, 0);

if (show_clock || bar_enabled || slideshow_enabled) {
if (show_clock || bar_enabled || slideshow_enabled || update_greeter) {
if (redraw_thread) {
struct timespec ts;
double s;
Expand Down Expand Up @@ -2659,3 +2669,19 @@ int main(int argc, char *argv[]) {

return 0;
}

void update_greeter_text() {
FILE *fp;
static char file_text[128];

memset(file_text,0,sizeof(file_text));

DEBUG("greeter_cmd is: [%s]\n", greeter_cmd);
if((fp = popen(greeter_cmd, "r")) == NULL)
return;

fread(file_text, sizeof(char), sizeof(file_text), fp);
pclose(fp);

greeter_text = file_text;
}
2 changes: 2 additions & 0 deletions i3lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
} \
} while (0)

void update_greeter_text();

#endif
4 changes: 4 additions & 0 deletions unlock_indicator.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extern int screen_number;
extern float refresh_rate;

extern bool show_clock;
extern bool update_greeter;
extern bool always_show_clock;
extern bool show_indicator;
extern int verif_align;
Expand Down Expand Up @@ -920,6 +921,9 @@ void render_lock(uint32_t *resolution, xcb_drawable_t drawable) {
}

if (greeter_text) {
if(update_greeter) {
update_greeter_text();
}
draw_data.greeter_text.show = true;
strncpy(draw_data.greeter_text.str, greeter_text, sizeof(draw_data.greeter_text.str) - 1);
draw_data.greeter_text.size = greeter_size;
Expand Down