From 5dc7159f214b639319a3be2c33503300fdf8f192 Mon Sep 17 00:00:00 2001 From: Ruby-Dragon <91497228+Ruby-Dragon@users.noreply.github.com> Date: Tue, 26 Apr 2022 12:07:55 -0700 Subject: [PATCH 1/7] add install and uninstall information to README.md --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f5467e..91e59f0 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,21 @@ make ### Arch Linux This project is in the AUR under [activate-linux-git](https://aur.archlinux.org/packages/activate-linux-git). -Install it using your favorite AUR helper. +Install/uninstall it using your favorite AUR helper. ### OpenSUSE (Open Build Service) This project is in the OBS under [activate-linux](https://software.opensuse.org//download.html?project=home%3AWoMspace&package=activate-linux). +### All Distros +``` +make install +activate_linux +``` + +## Uninstall (All Distros Method) +``` +make uninstall +``` # MacOS (Experimental) ## Dependencies From 7a565716f74985044dea333de330ddb352a5f334 Mon Sep 17 00:00:00 2001 From: Ruby-Dragon <91497228+Ruby-Dragon@users.noreply.github.com> Date: Sun, 15 May 2022 12:53:21 -0700 Subject: [PATCH 2/7] Update README.md --- README.md | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 696d0e9..6d9e9d2 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,8 @@ Install/uninstall it using your favorite AUR helper. ### OpenSUSE (Open Build Service) This project is in the OBS under [activate-linux](https://software.opensuse.org//download.html?project=home%3AWoMspace&package=activate-linux). -### All Distros -``` -make install -activate_linux -``` - -## Uninstall (All Distros Method) -``` -make uninstall -``` +### Other +You can use `make install` to install to /usr/bin, and `make uninstall` to remove it # MacOS (Horrific) ## Dependencies @@ -63,9 +55,6 @@ make > Note that the executable is located in `bin/` -### Installing -You can use `make install` to install to /usr/bin, and `make uninstall` to remove it - ## Wayland This works out of the box through XWayland, or alternatively you can use [this port of the project by Kljunas2](https://github.com/Kljunas2/activate-linux). From a9ee22d2d639400cd482e640281b36b0d221fb87 Mon Sep 17 00:00:00 2001 From: Ruby-Dragon <91497228+Ruby-Dragon@users.noreply.github.com> Date: Sun, 15 May 2022 13:36:14 -0700 Subject: [PATCH 3/7] add colors struct and usage --- src/activate_linux.c | 53 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/activate_linux.c b/src/activate_linux.c index 48b6a6a..20a7dba 100644 --- a/src/activate_linux.c +++ b/src/activate_linux.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -10,10 +11,20 @@ #include #include +//struct to hold rgb color +struct RGBAColor +{ + //rgba color values from 0 to 1 + float r; + float g; + float b; + float a; +}; + // draw text -void draw(cairo_t *cr, char *title, char *subtitle, float scale) { +void draw(cairo_t *cr, char *title, char *subtitle, float scale, struct RGBAColor color) { //set color - cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.35); + cairo_set_source_rgba(cr, color.r, color.g, color.b, color.g); // set font size, and scale up or down cairo_set_font_size(cr, 24 * scale); @@ -25,6 +36,30 @@ void draw(cairo_t *cr, char *title, char *subtitle, float scale) { cairo_show_text(cr, subtitle); } +void RGBAColor_from_string(struct RGBAColor* color, char* text) +{ + char* alpha = strtok(text, "-"); + if (alpha != NULL) + { + color->a = atof(alpha); + } + char* blue = strtok(NULL, "-"); + if (blue != NULL) + { + color->b = atof(blue); + } + char* green = strtok(NULL, "-"); + if (green != NULL) + { + color->g = atof(green); + } + char* red = strtok(NULL, "-"); + if (red != NULL) + { + color->r = atof(red); + } +} + int main(int argc, char *argv[]) { Display *d = XOpenDisplay(NULL); Window root = DefaultRootWindow(d); @@ -42,11 +77,15 @@ int main(int argc, char *argv[]) { return 1; } + //title and subtitle text char *title, *subtitle; int overlay_width = 340; int overlay_height = 120; + //color of text + struct RGBAColor text_color = {.r= 1.0, .g= 1.0, .b= 1.0, .a= 0.35}; + // default scale float scale = 1.0f; @@ -95,6 +134,12 @@ int main(int argc, char *argv[]) { scale = atof(argv[3]); break; + case (5): + title = argv[1]; + subtitle = argv[2]; + scale = atof(argv[3]); + break; + // if there are more than 3 arguments, print usage default: printf("More than needed arguments have been passed. This program only supports at most 3 arguments.\n"); @@ -163,7 +208,7 @@ int main(int argc, char *argv[]) { // cairo context surface[i] = cairo_xlib_surface_create(d, overlay[i], vinfo.visual, overlay_width, overlay_height); cairo_ctx[i] = cairo_create(surface[i]); - draw(cairo_ctx[i], title, subtitle, scale); + draw(cairo_ctx[i], title, subtitle, scale, text_color); } // wait for X events forever @@ -182,4 +227,4 @@ int main(int argc, char *argv[]) { XFree(si); XCloseDisplay(d); return 0; -} +} \ No newline at end of file From f1af1a64e1f1feca8438ead64d9f17f4539b20f0 Mon Sep 17 00:00:00 2001 From: Ruby-Dragon <91497228+Ruby-Dragon@users.noreply.github.com> Date: Sun, 15 May 2022 13:41:08 -0700 Subject: [PATCH 4/7] add colors option as arg --- src/activate_linux.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/activate_linux.c b/src/activate_linux.c index 20a7dba..5546d59 100644 --- a/src/activate_linux.c +++ b/src/activate_linux.c @@ -138,11 +138,12 @@ int main(int argc, char *argv[]) { title = argv[1]; subtitle = argv[2]; scale = atof(argv[3]); + RGBAColor_from_string(&text_color, argv[4]); break; // if there are more than 3 arguments, print usage default: - printf("More than needed arguments have been passed. This program only supports at most 3 arguments.\n"); + printf("More than needed arguments have been passed. This program only supports at most 4 arguments.\n"); return 1; } From a7028a8e2a1aaba313a2a9bf1880ddf924ee89dd Mon Sep 17 00:00:00 2001 From: Ruby-Dragon <91497228+Ruby-Dragon@users.noreply.github.com> Date: Sun, 15 May 2022 13:49:01 -0700 Subject: [PATCH 5/7] fix color bugs --- src/activate_linux.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/activate_linux.c b/src/activate_linux.c index 5546d59..23fd68f 100644 --- a/src/activate_linux.c +++ b/src/activate_linux.c @@ -24,7 +24,7 @@ struct RGBAColor // draw text void draw(cairo_t *cr, char *title, char *subtitle, float scale, struct RGBAColor color) { //set color - cairo_set_source_rgba(cr, color.r, color.g, color.b, color.g); + cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); // set font size, and scale up or down cairo_set_font_size(cr, 24 * scale); @@ -38,25 +38,25 @@ void draw(cairo_t *cr, char *title, char *subtitle, float scale, struct RGBAColo void RGBAColor_from_string(struct RGBAColor* color, char* text) { - char* alpha = strtok(text, "-"); - if (alpha != NULL) - { - color->a = atof(alpha); - } - char* blue = strtok(NULL, "-"); - if (blue != NULL) + char* red = strtok(text, "-"); + if (red != NULL) { - color->b = atof(blue); + color->r = atof(red); } char* green = strtok(NULL, "-"); if (green != NULL) { color->g = atof(green); } - char* red = strtok(NULL, "-"); - if (red != NULL) + char* blue = strtok(NULL, "-"); + if (green != NULL) { - color->r = atof(red); + color->b = atof(blue); + } + char* alpha = strtok(NULL, "-"); + if (alpha != NULL) + { + color->a = atof(alpha); } } From d7ba7eca05ef0c13df52383540308b317d0b1203 Mon Sep 17 00:00:00 2001 From: Ruby-Dragon <91497228+Ruby-Dragon@users.noreply.github.com> Date: Sun, 15 May 2022 13:52:35 -0700 Subject: [PATCH 6/7] add docs for color in ARGS.md --- ARGS.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ARGS.md b/ARGS.md index 19260dd..117b8da 100644 --- a/ARGS.md +++ b/ARGS.md @@ -2,11 +2,13 @@ Activate linux takes command line arguments for custom text and scaling. -There are 4 different options for command line arguments: a custom main message, scale percent, custom main and secondary message, or all 3 options. +There are 5 different options for command line arguments: a custom main message, scale percent, custom main and secondary message, all 3 options, or all 3 options and custom color. Scaling is used to display the message correctly on screens of different resolutions. 100% is based on 1080p. It also affects the offset from the corner of the screen so is not reccomended to be changed unless you are not using a 1080p screen. +Color is formatted in "r-g-b-a", with each number being a decimal from 0 to 1. Default is a light grey color. + ### Custom Main Message ``` @@ -31,4 +33,10 @@ note that scale is a percent represented as a floating point number, 1 being 100 ``` ./bin/activate_linux (main) (secondary) (scale) +``` + +### All 3 options and custom color + +``` +./bin/activate_linux (main) (secondary) (scale) (color) ``` \ No newline at end of file From fef0e7e33cf7c54a54ebdf760d91adc7e9c7d405 Mon Sep 17 00:00:00 2001 From: Ruby-Dragon <91497228+Ruby-Dragon@users.noreply.github.com> Date: Sun, 15 May 2022 13:56:07 -0700 Subject: [PATCH 7/7] add comments to code --- src/activate_linux.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/activate_linux.c b/src/activate_linux.c index 23fd68f..58b5026 100644 --- a/src/activate_linux.c +++ b/src/activate_linux.c @@ -36,8 +36,10 @@ void draw(cairo_t *cr, char *title, char *subtitle, float scale, struct RGBAColo cairo_show_text(cr, subtitle); } +//fill RGBAColor struct values from a string formatted in "r-g-b-a" from 0.0 to 1.0 void RGBAColor_from_string(struct RGBAColor* color, char* text) { + //split text into 4 parts along "-". If the input is not valid, use default setting char* red = strtok(text, "-"); if (red != NULL) { @@ -83,7 +85,7 @@ int main(int argc, char *argv[]) { int overlay_width = 340; int overlay_height = 120; - //color of text + //color of text - set default as light grey struct RGBAColor text_color = {.r= 1.0, .g= 1.0, .b= 1.0, .a= 0.35}; // default scale @@ -134,6 +136,7 @@ int main(int argc, char *argv[]) { scale = atof(argv[3]); break; + //4 arguments case (5): title = argv[1]; subtitle = argv[2];