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

View File

@@ -1,8 +1,8 @@
/* Choose where to apply light/dark mode */
#define PYWAL 1
#define EMACS 0
#define DWM 0
#define GTK 0
#define EMACS 1
#define DWM 1
#define GTK 1
/* Auto light/dark settings */
#define LIGHT_LOW_TRESH 60
@@ -10,80 +10,92 @@
#define REFRESH_TIME 5
/* Light color scheme */
#define LFG "#3c3836"
#define LBG "#fbf1c7"
#define LCURSOR LFG
#define LCONTRAST "#d65d0e"
#define LBLACK1 LFG
#define LBLACK2 DBG
#define LRED1 "#cc241d"
#define LRED2 "#9d0006"
#define LGREEN1 "#98971a"
#define LGREEN2 "#79740e"
#define LYELLOW1 "#d79921"
#define LYELLOW2 "#b57614"
#define LBLUE1 "#458588"
#define LBLUE2 "#076678"
#define LMAGENTA1 "#b16286"
#define LMAGENTA2 "#8f3f71"
#define LCYAN1 "#689d6a"
#define LCYAN2 "#427b58"
#define LWHITE1 LBG
#define LWHITE2 DFG
#define LROSEWATER "#dc8a78"
#define LFLAMINGO "#dd7878"
#define LPINK "#ea76cb"
#define LMAUVE "#8839ef"
#define LRED "#d20f39"
#define LMAROON "#e64553"
#define LPEACH "#fe640b"
#define LYELLOW "#df8e1d"
#define LGREEN "#40a02b"
#define LTEAL "#179299"
#define LSKY "#04a5e5"
#define LSAPPHIRE "#209fb5"
#define LBLUE "#1e66f5"
#define LLAVENDER "#7287fd"
#define LTEXT "#4c4f69"
#define LSUBTEXT1 "#5c5f77"
#define LSUBTEXT0 "#6c6f85"
#define LOVERLAY2 "#7c7f93"
#define LOVERLAY1 "#8c8fa1"
#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 LDWMTEXTFG LFG
#define LDWMBORDER LWHITE2
#define LDWMBORDERSEL LCONTRAST
#define LDWMTAGBG LCONTRAST
#define LDWMTAGFG LBG
#define LDWMTAGSELBG LBLUE1
#define LDWMTAGSELFG LBG
#define LDWMTITLEBG LBG
#define LDWMTITLEFG LCONTRAST
#define LDWMTITLESELBG LCONTRAST
#define LDWMTITLESELFG LBG
#define LDWMTEXTBG LBASE
#define LDWMTEXTFG LTEXT
#define LDWMBORDER LSURFACE1
#define LDWMBORDERSEL LMAROON
#define LDWMTAGBG LBASE
#define LDWMTAGFG LTEXT
#define LDWMTAGSELBG LCRUST
#define LDWMTAGSELFG LGREEN
#define LDWMTITLEBG LBASE
#define LDWMTITLEFG LTEXT
#define LDWMTITLESELBG LSURFACE0
#define LDWMTITLESELFG LGREEN
#define LGTKTHEME "Gruvbox-light"
#define LGTKTHEME "Catppuccin-Latte-Standard-Blue-light"
/* Dark color scheme */
#define DFG "#ebdbb2"
#define DBG "#282828"
#define DCURSOR DFG
#define DCONTRAST "#d65d0e"
#define DBLACK1 DBG
#define DBLACK2 LFG
#define DRED1 LRED1
#define DRED2 "#fb4934"
#define DGREEN1 LGREEN1
#define DGREEN2 "#b8bb26"
#define DYELLOW1 LYELLOW1
#define DYELLOW2 "#fabd2f"
#define DBLUE1 LBLUE1
#define DBLUE2 "#83a598"
#define DMAGENTA1 LMAGENTA1
#define DMAGENTA2 "#d3869b"
#define DCYAN1 LCYAN1
#define DCYAN2 "#8ec07c"
#define DWHITE1 DFG
#define DWHITE2 LBG
#define DROSEWATER "#f4dbd6"
#define DFLAMINGO "#f0c6c6"
#define DPINK "#f5bde6"
#define DMAUVE "#c6a0f6"
#define DRED "#ed8796"
#define DMAROON "#ee99a0"
#define DPEACH "#f5a97f"
#define DYELLOW "#eed49f"
#define DGREEN "#a6da95"
#define DTEAL "#8bd5ca"
#define DSKY "#91d7e3"
#define DSAPPHIRE "#7dc4e4"
#define DBLUE "#8aadf4"
#define DLAVENDER "#b7bdf8"
#define DTEXT "#cad3f5"
#define DSUBTEXT1 "#b8c0e0"
#define DSUBTEXT0 "#a5adcb"
#define DOVERLAY2 "#939ab7"
#define DOVERLAY1 "#8087a2"
#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 DDWMTEXTFG DFG
#define DDWMBORDER DBLACK2
#define DDWMBORDERSEL DCONTRAST
#define DDWMTAGBG DCONTRAST
#define DDWMTAGFG DFG
#define DDWMTAGSELBG DBLUE1
#define DDWMTAGSELFG DFG
#define DDWMTITLEBG DBG
#define DDWMTITLEFG DCONTRAST
#define DDWMTITLESELBG DCONTRAST
#define DDWMTITLESELFG DFG
#define DDWMTEXTBG DBASE
#define DDWMTEXTFG DTEXT
#define DDWMBORDER DSURFACE1
#define DDWMBORDERSEL DMAROON
#define DDWMTAGBG DBASE
#define DDWMTAGFG DTEXT
#define DDWMTAGSELBG DCRUST
#define DDWMTAGSELFG DGREEN
#define DDWMTITLEBG DBASE
#define DDWMTITLEFG DTEXT
#define DDWMTITLESELBG DSURFACE0
#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 */
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(;;){
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
@@ -25,50 +28,67 @@
smart light switch, use the time, or whatever you want! Just make a function
called lightvalue which returns an int from 0 to 100. */
// light returned based on camera output
// int lightvalue(){
// double brightness;
int lightvalue(){
double brightness;
// sd_bus *userbus=NULL;
// sd_bus_message *sdbusmessage = NULL;
sd_bus *userbus=NULL;
sd_bus_message *sdbusmessage = NULL;
// /* start clight if it isn't running */
// 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 */
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);
}
// /* get user dbus */
// sd_bus_default_user(&userbus);
/* get user dbus */
sd_bus_default_user(&userbus);
/* refresh clight */
sd_bus_call_method(userbus,
"org.clight.clight",
"/org/clight/clight",
"org.clight.clight",
"Capture",
NULL,
NULL,
"bb",
"0",
"1");
// /* refresh clight */
// sd_bus_call_method(userbus,
// "org.clight.clight",
// "/org/clight/clight",
// "org.clight.clight",
// "Capture",
// NULL,
// NULL,
// "bb",
// "0",
// "1");
/* get clight ambient light value */
sd_bus_get_property(userbus,
"org.clight.clight",
"/org/clight/clight",
"org.clight.clight",
"AmbientBr",
NULL,
&sdbusmessage,
"d");
// /* get clight ambient light value */
// sd_bus_get_property(userbus,
// "org.clight.clight",
// "/org/clight/clight",
// "org.clight.clight",
// "AmbientBr",
// NULL,
// &sdbusmessage,
// "d");
sd_bus_message_read(sdbusmessage, "d", &brightness);
// sd_bus_message_read(sdbusmessage, "d", &brightness);
sd_bus_message_unref(sdbusmessage);
sd_bus_unref(userbus);
// sd_bus_message_unref(sdbusmessage);
// 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;
}