Add -d option to specify delay
This commit is contained in:
parent
539febb2df
commit
70c3b7c5c0
2 changed files with 28 additions and 4 deletions
|
@ -16,7 +16,7 @@ struct chayang {
|
||||||
struct wl_list seats;
|
struct wl_list seats;
|
||||||
|
|
||||||
bool running;
|
bool running;
|
||||||
int64_t start_time_ms;
|
int64_t delay_ms, start_time_ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct chayang_output {
|
struct chayang_output {
|
||||||
|
|
30
main.c
30
main.c
|
@ -1,3 +1,4 @@
|
||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -12,8 +13,6 @@
|
||||||
#include "viewporter-protocol.h"
|
#include "viewporter-protocol.h"
|
||||||
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
#include "wlr-layer-shell-unstable-v1-protocol.h"
|
||||||
|
|
||||||
#define DIM_DELAY_MS 3000
|
|
||||||
|
|
||||||
static void repaint_output(struct chayang_output *output);
|
static void repaint_output(struct chayang_output *output);
|
||||||
|
|
||||||
static int64_t now_ms(void) {
|
static int64_t now_ms(void) {
|
||||||
|
@ -37,7 +36,7 @@ static const struct wl_callback_listener frame_callback_listener = {
|
||||||
|
|
||||||
static void repaint_output(struct chayang_output *output) {
|
static void repaint_output(struct chayang_output *output) {
|
||||||
int64_t delta = now_ms() - output->chayang->start_time_ms;
|
int64_t delta = now_ms() - output->chayang->start_time_ms;
|
||||||
double progress = (double)delta / DIM_DELAY_MS;
|
double progress = (double)delta / output->chayang->delay_ms;
|
||||||
if (progress >= 1) {
|
if (progress >= 1) {
|
||||||
output->chayang->running = false;
|
output->chayang->running = false;
|
||||||
return;
|
return;
|
||||||
|
@ -251,6 +250,31 @@ int main(int argc, char *argv[]) {
|
||||||
wl_list_init(&state.outputs);
|
wl_list_init(&state.outputs);
|
||||||
wl_list_init(&state.seats);
|
wl_list_init(&state.seats);
|
||||||
|
|
||||||
|
double delay_sec = 3;
|
||||||
|
while (1) {
|
||||||
|
int opt = getopt(argc, argv, "hd:");
|
||||||
|
if (opt < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (opt) {
|
||||||
|
case 'd':
|
||||||
|
char *end = NULL;
|
||||||
|
errno = 0;
|
||||||
|
delay_sec = strtod(optarg, &end);
|
||||||
|
if (errno != 0 || end == optarg || end != &optarg[strlen(optarg)]) {
|
||||||
|
fprintf(stderr, "invalid -d value\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "usage: chayang [-d seconds]\n");
|
||||||
|
return opt == 'h' ? 0 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state.delay_ms = delay_sec * 1000;
|
||||||
|
|
||||||
struct wl_display *display = wl_display_connect(NULL);
|
struct wl_display *display = wl_display_connect(NULL);
|
||||||
if (display == NULL) {
|
if (display == NULL) {
|
||||||
fprintf(stderr, "failed to connect to display\n");
|
fprintf(stderr, "failed to connect to display\n");
|
||||||
|
|
Loading…
Add table
Reference in a new issue