dusk changes when the time changes

This commit is contained in:
2023-09-17 19:51:03 +02:00
parent 3406fa27d9
commit 889e11cd47
4 changed files with 188 additions and 153 deletions

View File

@@ -104,8 +104,8 @@ void applypywal(){
} }
void applyemacs(){ void applyemacs(){
char buffer[128]; char buffer[256];
sprintf(buffer, "emacsclient --eval \" (load-theme '%s)\"", emacstheme); sprintf(buffer, "emacsclient --eval \" (progn (setq catppuccin-flavor '%s) (catppuccin-reload))\"", emacstheme);
system(buffer); system(buffer);
} }
@@ -148,7 +148,7 @@ void applydwm(){
/* Apply xresources with the xrdb patch and hte dwmc patch */ /* Apply xresources with the xrdb patch and hte dwmc patch */
system("xrdb -merge ~/.cache/dusk/xresources"); system("xrdb -merge ~/.cache/dusk/xresources");
system("~/src/dwm/patch/dwmc xrdb"); system("~/.dwm/patch/dwmc xrdb");
/* Change x root window color */ /* Change x root window color */
sprintf(buffer, "xsetroot -solid \"%s\"", bg); sprintf(buffer, "xsetroot -solid \"%s\"", bg);
@@ -177,26 +177,26 @@ void changescheme(int color){
switch (color) { switch (color) {
case 1: { case 1: {
/* light mode */ /* light mode */
strcpy(fg, LFG); strcpy(fg, LTEXT);
strcpy(bg, LBG); strcpy(bg, LBASE);
strcpy(cursor, LCURSOR); strcpy(cursor, LTEXT);
strcpy(contrast, LCONTRAST); strcpy(contrast, LGREEN);
strcpy(black1, LBLACK1); strcpy(black1, LCRUST);
strcpy(black2, LBLACK2); strcpy(black2, LCRUST);
strcpy(red1, LRED1); strcpy(red1, LRED);
strcpy(red2, LRED2); strcpy(red2, LRED);
strcpy(green1, LGREEN1); strcpy(green1, LGREEN);
strcpy(green2, LGREEN2); strcpy(green2, LGREEN);
strcpy(yellow1, LYELLOW1); strcpy(yellow1, LYELLOW);
strcpy(yellow2, LYELLOW2); strcpy(yellow2, LYELLOW);
strcpy(blue1, LBLUE1); strcpy(blue1, LBLUE);
strcpy(blue2, LBLUE2); strcpy(blue2, LBLUE);
strcpy(magenta1, LMAGENTA1); strcpy(magenta1, LPINK);
strcpy(magenta2, LMAGENTA2); strcpy(magenta2, LPINK);
strcpy(cyan1, LCYAN1); strcpy(cyan1, LTEAL);
strcpy(cyan2, LCYAN2); strcpy(cyan2, LTEAL);
strcpy(white1, LWHITE1); strcpy(white1, LTEXT);
strcpy(white2, LWHITE2); strcpy(white2, LTEXT);
strcpy(emacstheme, LEMACS); strcpy(emacstheme, LEMACS);
strcpy(dwmtextbg, LDWMTEXTBG); strcpy(dwmtextbg, LDWMTEXTBG);
strcpy(dwmtextfg, LDWMTEXTFG); strcpy(dwmtextfg, LDWMTEXTFG);
@@ -216,26 +216,26 @@ void changescheme(int color){
} }
case 0: { case 0: {
/* dark mode */ /* dark mode */
strcpy(fg, DFG); strcpy(fg, DTEXT);
strcpy(bg, DBG); strcpy(bg, DBASE);
strcpy(cursor, DCURSOR); strcpy(cursor, DTEXT);
strcpy(contrast, DCONTRAST); strcpy(contrast, DBLUE);
strcpy(black1, DBLACK1); strcpy(black1, DCRUST);
strcpy(black2, DBLACK2); strcpy(black2, DCRUST);
strcpy(red1, DRED1); strcpy(red1, DRED);
strcpy(red2, DRED2); strcpy(red2, DRED);
strcpy(green1, DGREEN1); strcpy(green1, DGREEN);
strcpy(green2, DGREEN2); strcpy(green2, DGREEN);
strcpy(yellow1, DYELLOW1); strcpy(yellow1, DYELLOW);
strcpy(yellow2, DYELLOW2); strcpy(yellow2, DYELLOW);
strcpy(blue1, DBLUE1); strcpy(blue1, DBLUE);
strcpy(blue2, DBLUE2); strcpy(blue2, DBLUE);
strcpy(magenta1, DMAGENTA1); strcpy(magenta1, DPINK);
strcpy(magenta2, DMAGENTA2); strcpy(magenta2, DPINK);
strcpy(cyan1, DCYAN1); strcpy(cyan1, DTEAL);
strcpy(cyan2, DCYAN2); strcpy(cyan2, DTEAL);
strcpy(white1, DWHITE1); strcpy(white1, DTEXT);
strcpy(white2, DWHITE2); strcpy(white2, DTEXT);
strcpy(emacstheme, DEMACS); strcpy(emacstheme, DEMACS);
strcpy(dwmtextbg, DDWMTEXTBG); strcpy(dwmtextbg, DDWMTEXTBG);
strcpy(dwmtextfg, DDWMTEXTFG); strcpy(dwmtextfg, DDWMTEXTFG);

View File

@@ -1,8 +1,8 @@
/* Choose where to apply light/dark mode */ /* Choose where to apply light/dark mode */
#define PYWAL 1 #define PYWAL 1
#define EMACS 0 #define EMACS 1
#define DWM 0 #define DWM 1
#define GTK 0 #define GTK 1
/* Auto light/dark settings */ /* Auto light/dark settings */
#define LIGHT_LOW_TRESH 60 #define LIGHT_LOW_TRESH 60
@@ -10,80 +10,92 @@
#define REFRESH_TIME 5 #define REFRESH_TIME 5
/* Light color scheme */ /* Light color scheme */
#define LFG "#3c3836" #define LROSEWATER "#dc8a78"
#define LBG "#fbf1c7" #define LFLAMINGO "#dd7878"
#define LCURSOR LFG #define LPINK "#ea76cb"
#define LCONTRAST "#d65d0e" #define LMAUVE "#8839ef"
#define LBLACK1 LFG #define LRED "#d20f39"
#define LBLACK2 DBG #define LMAROON "#e64553"
#define LRED1 "#cc241d" #define LPEACH "#fe640b"
#define LRED2 "#9d0006" #define LYELLOW "#df8e1d"
#define LGREEN1 "#98971a" #define LGREEN "#40a02b"
#define LGREEN2 "#79740e" #define LTEAL "#179299"
#define LYELLOW1 "#d79921" #define LSKY "#04a5e5"
#define LYELLOW2 "#b57614" #define LSAPPHIRE "#209fb5"
#define LBLUE1 "#458588" #define LBLUE "#1e66f5"
#define LBLUE2 "#076678" #define LLAVENDER "#7287fd"
#define LMAGENTA1 "#b16286" #define LTEXT "#4c4f69"
#define LMAGENTA2 "#8f3f71" #define LSUBTEXT1 "#5c5f77"
#define LCYAN1 "#689d6a" #define LSUBTEXT0 "#6c6f85"
#define LCYAN2 "#427b58" #define LOVERLAY2 "#7c7f93"
#define LWHITE1 LBG #define LOVERLAY1 "#8c8fa1"
#define LWHITE2 DFG #define LOVERLAY0 "#9ca0b0"
#define LSURFACE2 "#acb0be"
#define LSURFACE1 "#bcc0cc"
#define LSURFACE0 "#ccd0da"
#define LBASE "#eff1f5"
#define LMANTLE "#e6e9ef"
#define LCRUST "#dce0e8"
#define LEMACS "gruvbox-light-medium" #define LEMACS "latte"
#define LDWMTEXTBG LBG #define LDWMTEXTBG LBASE
#define LDWMTEXTFG LFG #define LDWMTEXTFG LTEXT
#define LDWMBORDER LWHITE2 #define LDWMBORDER LSURFACE1
#define LDWMBORDERSEL LCONTRAST #define LDWMBORDERSEL LMAROON
#define LDWMTAGBG LCONTRAST #define LDWMTAGBG LBASE
#define LDWMTAGFG LBG #define LDWMTAGFG LTEXT
#define LDWMTAGSELBG LBLUE1 #define LDWMTAGSELBG LCRUST
#define LDWMTAGSELFG LBG #define LDWMTAGSELFG LGREEN
#define LDWMTITLEBG LBG #define LDWMTITLEBG LBASE
#define LDWMTITLEFG LCONTRAST #define LDWMTITLEFG LTEXT
#define LDWMTITLESELBG LCONTRAST #define LDWMTITLESELBG LSURFACE0
#define LDWMTITLESELFG LBG #define LDWMTITLESELFG LGREEN
#define LGTKTHEME "Gruvbox-light" #define LGTKTHEME "Catppuccin-Latte-Standard-Blue-light"
/* Dark color scheme */ /* Dark color scheme */
#define DFG "#ebdbb2" #define DROSEWATER "#f4dbd6"
#define DBG "#282828" #define DFLAMINGO "#f0c6c6"
#define DCURSOR DFG #define DPINK "#f5bde6"
#define DCONTRAST "#d65d0e" #define DMAUVE "#c6a0f6"
#define DBLACK1 DBG #define DRED "#ed8796"
#define DBLACK2 LFG #define DMAROON "#ee99a0"
#define DRED1 LRED1 #define DPEACH "#f5a97f"
#define DRED2 "#fb4934" #define DYELLOW "#eed49f"
#define DGREEN1 LGREEN1 #define DGREEN "#a6da95"
#define DGREEN2 "#b8bb26" #define DTEAL "#8bd5ca"
#define DYELLOW1 LYELLOW1 #define DSKY "#91d7e3"
#define DYELLOW2 "#fabd2f" #define DSAPPHIRE "#7dc4e4"
#define DBLUE1 LBLUE1 #define DBLUE "#8aadf4"
#define DBLUE2 "#83a598" #define DLAVENDER "#b7bdf8"
#define DMAGENTA1 LMAGENTA1 #define DTEXT "#cad3f5"
#define DMAGENTA2 "#d3869b" #define DSUBTEXT1 "#b8c0e0"
#define DCYAN1 LCYAN1 #define DSUBTEXT0 "#a5adcb"
#define DCYAN2 "#8ec07c" #define DOVERLAY2 "#939ab7"
#define DWHITE1 DFG #define DOVERLAY1 "#8087a2"
#define DWHITE2 LBG #define DOVERLAY0 "#6e738d"
#define DSURFACE2 "#5b6078"
#define DSURFACE1 "#494d64"
#define DSURFACE0 "#363a4f"
#define DBASE "#24273a"
#define DMANTLE "#1e2030"
#define DCRUST "#181926"
#define DEMACS "gruvbox-dark-medium" #define DEMACS "macchiato"
#define DDWMTEXTBG DBG #define DDWMTEXTBG DBASE
#define DDWMTEXTFG DFG #define DDWMTEXTFG DTEXT
#define DDWMBORDER DBLACK2 #define DDWMBORDER DSURFACE1
#define DDWMBORDERSEL DCONTRAST #define DDWMBORDERSEL DMAROON
#define DDWMTAGBG DCONTRAST #define DDWMTAGBG DBASE
#define DDWMTAGFG DFG #define DDWMTAGFG DTEXT
#define DDWMTAGSELBG DBLUE1 #define DDWMTAGSELBG DCRUST
#define DDWMTAGSELFG DFG #define DDWMTAGSELFG DGREEN
#define DDWMTITLEBG DBG #define DDWMTITLEBG DBASE
#define DDWMTITLEFG DCONTRAST #define DDWMTITLEFG DTEXT
#define DDWMTITLESELBG DCONTRAST #define DDWMTITLESELBG DSURFACE0
#define DDWMTITLESELFG DFG #define DDWMTITLESELFG DGREEN
#define DGTKTHEME "Gruvbox-dark" #define DGTKTHEME "Catppuccin-Macchiato-Standard-Blue-dark"

View File

@@ -38,7 +38,10 @@ int main(int argc, char *argv[]) {
if (argc == 1) { /* Automatically change themes when no argument is given */ if (argc == 1) { /* Automatically change themes when no argument is given */
changescheme(1); /* Start with light theme as default */ if (lightvalue() > 50)
changescheme(1); /* Start with light theme if brightness higher than 50 */
else
changescheme(0);
for(;;){ for(;;){
light=lightvalue(); /* Get ambient light */ light=lightvalue(); /* Get ambient light */

View File

@@ -1,3 +1,6 @@
#include <time.h>
#include <stdio.h>
/* /*
Copyright 2021 Karl Ragnar Giese, karl@giese.no Copyright 2021 Karl Ragnar Giese, karl@giese.no
@@ -25,50 +28,67 @@
smart light switch, use the time, or whatever you want! Just make a function smart light switch, use the time, or whatever you want! Just make a function
called lightvalue which returns an int from 0 to 100. */ called lightvalue which returns an int from 0 to 100. */
// light returned based on camera output
// int lightvalue(){
// double brightness;
int lightvalue(){ // sd_bus *userbus=NULL;
double brightness; // sd_bus_message *sdbusmessage = NULL;
sd_bus *userbus=NULL; // /* start clight if it isn't running */
sd_bus_message *sdbusmessage = NULL; // if(system("pidof -x clight > /dev/null") != 0){
// printf("%s\n", "starting clight");
// system("clight --no-gamma --no-dimmer --no-dpms --no-kbd --no-auto-calib &");
// sleep(5);
// }
/* start clight if it isn't running */ // /* get user dbus */
if(system("pidof -x clight > /dev/null") != 0){ // sd_bus_default_user(&userbus);
printf("%s\n", "starting clight");
system("clight --no-gamma --no-dimmer --no-dpms --no-kbd --no-auto-calib &");
sleep(5);
}
/* get user dbus */ // /* refresh clight */
sd_bus_default_user(&userbus); // sd_bus_call_method(userbus,
// "org.clight.clight",
/* refresh clight */ // "/org/clight/clight",
sd_bus_call_method(userbus, // "org.clight.clight",
"org.clight.clight", // "Capture",
"/org/clight/clight", // NULL,
"org.clight.clight", // NULL,
"Capture", // "bb",
NULL, // "0",
NULL, // "1");
"bb",
"0",
"1");
/* get clight ambient light value */ // /* get clight ambient light value */
sd_bus_get_property(userbus, // sd_bus_get_property(userbus,
"org.clight.clight", // "org.clight.clight",
"/org/clight/clight", // "/org/clight/clight",
"org.clight.clight", // "org.clight.clight",
"AmbientBr", // "AmbientBr",
NULL, // NULL,
&sdbusmessage, // &sdbusmessage,
"d"); // "d");
sd_bus_message_read(sdbusmessage, "d", &brightness); // sd_bus_message_read(sdbusmessage, "d", &brightness);
sd_bus_message_unref(sdbusmessage); // sd_bus_message_unref(sdbusmessage);
sd_bus_unref(userbus); // sd_bus_unref(userbus);
return brightness * 100; /* return brightness as int from 0-100 */ // return brightness * 100; /* return brightness as int from 0-100 */
// }
int lightvalue() {
int brightness = 0;
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
if (timeinfo->tm_hour > 6 && timeinfo->tm_hour < 19)
brightness = 100;
printf("[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
return brightness;
} }