From 3a836137bd76589725e60064bc4f923ff251ba53 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 19 Jul 2014 04:02:19 +0300 Subject: [PATCH] layer position config, r2 release --- Makefile | 2 +- liveinfo.pxml | 4 +- main.c | 108 +++++++++++++++++++++++++++++++++++++++++--------- readme.txt | 11 ++++- run.sh | 9 +++-- update_pnd.sh | 2 +- 6 files changed, 110 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 7bae7b7..bc3e5f0 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,6 @@ custom: custom.c $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) clean: - $(RM) liveinfo $(OBJS) + $(RM) liveinfo custom $(OBJS) .PHONY: all clean diff --git a/liveinfo.pxml b/liveinfo.pxml index 5ea3c02..bb430c6 100644 --- a/liveinfo.pxml +++ b/liveinfo.pxml @@ -4,7 +4,7 @@ Live system info - + @@ -25,7 +25,7 @@ See documentation for information about what each number means. - + diff --git a/main.c b/main.c index 010f63c..4a8b952 100644 --- a/main.c +++ b/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -32,17 +33,21 @@ #define SCREEN_HEIGHT 480 #define WIDTH 80 #define HEIGHT 480 -#define MEM_SIZE (((WIDTH * HEIGHT * 2 * 2) + 0xfff) & ~0xfff) #define Y_STEP 9 static struct fb_var_screeninfo g_vi; static uint16_t *g_screen_base, *g_screen; +static struct { + int x, y, w, h; +} g_layer; +static unsigned int g_mem_size; static unsigned int g_old_mem; static int g_flip_id; static int g_exit, g_hide; static pthread_cond_t g_cond; #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#define PAGE_ALIGN(x) (((x) + 0xfff) & ~0xfff) #define IS_START(buf, str) \ !strncmp(buf, str, sizeof(str) - 1) @@ -78,8 +83,9 @@ static int setup_layer(int fd) } g_old_mem = mi.size; - if (mi.size < MEM_SIZE) { - mi.size = MEM_SIZE; + g_mem_size = PAGE_ALIGN(g_layer.w * g_layer.h * 2 * 2); + if (mi.size < g_mem_size) { + mi.size = g_mem_size; ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); if (ret < 0) { perror("ioctl SETUP_MEM"); @@ -87,10 +93,13 @@ static int setup_layer(int fd) } } - pi.pos_x = SCREEN_WIDTH - WIDTH; - pi.pos_y = 0; - pi.out_width = WIDTH; - pi.out_height = HEIGHT; + printf("layer: %d %d %d %d\n", + g_layer.x, g_layer.y, g_layer.w, g_layer.h); + + pi.pos_x = g_layer.x; + pi.pos_y = g_layer.y; + pi.out_width = g_layer.w; + pi.out_height = g_layer.h; ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi); if (ret < 0) { perror("ioctl OMAPFB_SETUP_PLANE (e1)"); @@ -103,9 +112,9 @@ static int setup_layer(int fd) return 1; } - g_vi.xres = g_vi.xres_virtual = WIDTH; - g_vi.yres = HEIGHT; - g_vi.yres_virtual = HEIGHT * 2; + g_vi.xres = g_vi.xres_virtual = g_layer.w; + g_vi.yres = g_layer.h; + g_vi.yres_virtual = g_layer.h * 2; g_vi.bits_per_pixel = 16; ret = ioctl(fd, FBIOPUT_VSCREENINFO, &g_vi); @@ -131,14 +140,14 @@ static int setup_layer(int fd) return 1; } - g_screen_base = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, + g_screen_base = mmap(NULL, g_mem_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (g_screen_base == MAP_FAILED) { perror("mmap"); g_screen = g_screen_base = NULL; return 1; } - clear_bytes(g_screen_base, MEM_SIZE); + clear_bytes(g_screen_base, g_mem_size); g_screen = g_screen_base; g_flip_id = 0; @@ -171,7 +180,7 @@ static void remove_layer(int fd) int ret; if (g_screen_base != NULL) { - munmap(g_screen_base, MEM_SIZE); + munmap(g_screen_base, g_mem_size); g_screen = g_screen_base = NULL; } @@ -201,10 +210,10 @@ out:; static void flip_fb(int fd) { - g_vi.yoffset = g_flip_id * HEIGHT; + g_vi.yoffset = g_flip_id * g_layer.h; ioctl(fd, FBIOPAN_DISPLAY, &g_vi); g_flip_id ^= 1; - g_screen = g_screen_base + g_flip_id * WIDTH * HEIGHT; + g_screen = g_screen_base + g_flip_id * g_layer.w * g_layer.h; } static void handle_term(int num) @@ -283,8 +292,65 @@ static int handle_socket(int sock) return 0; } -#define s_printf(x, y, fmt, ...) \ - basic_text_out16(g_screen, WIDTH, x, y, fmt, ##__VA_ARGS__); +static void default_config(void) +{ + g_layer.x = SCREEN_WIDTH - WIDTH; + g_layer.y = 0; + g_layer.w = WIDTH; + g_layer.h = HEIGHT; +} + +static void handle_config(void) +{ + char buf[256], *p; + int x, y, v; + FILE *f; + + default_config(); + + f = fopen("config.cfg", "r"); + if (f == NULL) + return; + + while ((p = fgets(buf, sizeof(buf), f))) { + while (isspace(*p)) + p++; + if (*p == '#' || *p == ';' || *p == 0) + continue; + + if (sscanf(p, "position = %d %d", &x, &y) == 2) { + g_layer.x = x; + g_layer.y = y; + } + else { + printf("unhandled config entry: '%s'\n", p); + } + } + fclose(f); + + v = SCREEN_WIDTH - g_layer.x; + if (v <= 0) { + printf("bad x position in config: %d\n", g_layer.x); + default_config(); + return; + } + if (v < WIDTH) + g_layer.w = v; + + v = SCREEN_HEIGHT - g_layer.y; + if (v <= 0) { + printf("bad y position in config: %d\n", g_layer.y); + default_config(); + return; + } + if (v < HEIGHT) + g_layer.h = v; +} + +#define s_printf(x, y, fmt, ...) do { \ + if ((y) <= g_layer.h - 8) \ + basic_text_out16(g_screen, g_layer.w, x, y, fmt, ##__VA_ARGS__); \ +} while (0) static int read_int_file(const char *fn, int *val) { @@ -316,7 +382,10 @@ static void clear_bytes(void *mem, int bytes) static void clear(int h) { - clear_bytes(g_screen, WIDTH * h * 2); + if (h > g_layer.h) + h = g_layer.h; + + clear_bytes(g_screen, g_layer.w * h * 2); } struct proc_stat { @@ -766,6 +835,9 @@ int main(int argc, char *argv[]) return ret == 4 ? 0 : 1; } + // load the config + handle_config(); + fd = open(fbname, O_RDWR); if (fd == -1) { fprintf(stderr, "open %s: ", fbname); diff --git a/readme.txt b/readme.txt index acc9149..8bb2aae 100644 --- a/readme.txt +++ b/readme.txt @@ -44,6 +44,13 @@ Fields T: 23.2C battery temperature +Configuration +------------- + +Currently only the layer's position can be changed by editing config.cfg +in appdata (file is automatically created on first run). + + Controlling live info --------------------- @@ -51,6 +58,7 @@ It's possible to hide Live info by sending it USR1 signal and show it again by sending the same signal. This can be done by simply running "killall -USR1 liveinfo" command. This command can also be bound to xfce keyboard shortcuts or similar. + Sending the TERM signal ("killall liveinfo") causes it to cleanly exit (sending it KILL / -9 signal will leave the layer enabled and visible, so is not recommended). @@ -80,4 +88,5 @@ Other understood commands are: License ------- -3-clause BSD. Source code included in pnd itself. +3-clause BSD, see COPYING file. +Source code is included in pnd itself. diff --git a/run.sh b/run.sh index e54a444..143b52f 100755 --- a/run.sh +++ b/run.sh @@ -1,10 +1,14 @@ #!/bin/sh +NAME="Live system info" MSG="Reserved OMAP video layer requires root access, please enter the password." +cp -n config.cfg.default config.cfg + if test -f /etc/slackware-version; then - ktsuss -m "$MSG" ./liveinfo + # ktsuss -m "$MSG" ./liveinfo + gksu -D "$NAME" -m "$MSG" ./liveinfo else @@ -14,7 +18,6 @@ else exit 1 fi - gksudo -D "SGX driver installer" \ - -m "$MSG" ./liveinfo + gksudo -D "$NAME" -m "$MSG" ./liveinfo fi diff --git a/update_pnd.sh b/update_pnd.sh index 1281ce7..8ad2af0 100755 --- a/update_pnd.sh +++ b/update_pnd.sh @@ -9,5 +9,5 @@ fi rm -f *.o mkdir -p /tmp/liveinfo_git mv .git /tmp/liveinfo_git/ -$PND_MAKE -p /tmp/liveinfo.pnd -d . -x liveinfo.pxml -i liveinfo.png -c +$PND_MAKE -p /tmp/liveinfo.pnd -d . -x liveinfo.pxml -i liveinfo.png -c || true mv /tmp/liveinfo_git/.git . -- 2.39.2