add switch to use the dark gtk theme
Since some time now, GTK3 themes can ship an optional "dark" variant and applications like picture viewers can make use of such a variant to appear dark (to not distract from the picture) without overwriting the current theme (and risking optical breakage). While wofi is not a picture viewer it may still be desirable to use a dark theme, for example to contrast the (light) application displaying in the background. Of course, wofi can already be fully customized through CSS and/or the colors file, but using the existing dark variant may be easier than fully restyling it, if all you want is a darker appearance. The only way to set an arbitrary GTK application to use the dark theme seems to be setting an environment variable, but that bears two problems: For one, one needs to specify the full theme + dark modifier in the variable, so one would have to keep the global GTK theme and the one used by wofi manually in sync. More critical though, the environment variable would be propagated to the programs wofi launches (for now at least). That would lead to all GTK applications launched through wofi to use the dark theme, which may not be desirable. Wofi could also unset that variable before launching a program, but at this point adding a simple switch is probably easier. Side note: It may be that there is some way to configure the CSS file to include the CSS of the dark variant of the current theme, but I have not been able to find out how. Gnome-terminal uses a switch like this too (just with dconf), so this may just be the way to go.
This commit is contained in:
parent
7755727cb6
commit
dc58ddbfb8
@ -103,6 +103,9 @@ Specifies the number of columns to display, default is 1.
|
||||
.TP
|
||||
.B \-O, \-\-sort\-order=\fIORDER\fR
|
||||
Specifies the default sort order. There are currently two orders, default and alphabetical. See \fBwofi\fR(7) for details.
|
||||
.TP
|
||||
.B \-G, \-\-gtk\-dark
|
||||
Instructs wofi to use the dark variant of the current GTK theme, if available.
|
||||
|
||||
.SH CONFIGURATION
|
||||
Wofi has 3 main files used for configuration. All files are completely optional.
|
||||
|
@ -100,6 +100,9 @@ Specifies the number of columns to display, default is 1.
|
||||
.B sort_order=\fIORDER\fR
|
||||
Specifies the default sort order. There are currently two orders, default and alphabetical. See \fBwofi\fR(7) for details.
|
||||
.TP
|
||||
.B gtk_dark=\fIBOOL\fR
|
||||
If true, instructs wofi to use the dark variant of the current GTK theme (if available). Default is false.
|
||||
.TP
|
||||
.B orientation=\fIORIENTATION\fR
|
||||
Specifies the orientation, it can be either horizontal or vertical, default is vertical.
|
||||
.TP
|
||||
|
22
src/main.c
22
src/main.c
@ -87,6 +87,7 @@ static void print_usage(char** argv) {
|
||||
printf("--lines\t\t-L\tSets the height in number of lines\n");
|
||||
printf("--columns\t-w\tSets the number of columns to display\n");
|
||||
printf("--sort-order\t-O\tSets the sort order\n");
|
||||
printf("--gtk-dark\t-G\tUses the dark variant of the current GTK theme\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -394,6 +395,12 @@ int main(int argc, char** argv) {
|
||||
.flag = NULL,
|
||||
.val = 'O'
|
||||
},
|
||||
{
|
||||
.name = "gtk-dark",
|
||||
.has_arg = no_argument,
|
||||
.flag = NULL,
|
||||
.val = 'G'
|
||||
},
|
||||
{
|
||||
.name = NULL,
|
||||
.has_arg = 0,
|
||||
@ -427,13 +434,14 @@ int main(int argc, char** argv) {
|
||||
char* lines = NULL;
|
||||
char* columns = NULL;
|
||||
char* sort_order = NULL;
|
||||
char* gtk_dark = NULL;
|
||||
|
||||
struct wl_list options;
|
||||
wl_list_init(&options);
|
||||
struct option_node* node;
|
||||
|
||||
int opt;
|
||||
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:iqvl:aD:L:w:O:", opts, NULL)) != -1) {
|
||||
while((opt = getopt_long(argc, argv, "hfc:s:C:dS:W:H:p:x:y:nImk:t:P::ebM:iqvl:aD:L:w:O:G", opts, NULL)) != -1) {
|
||||
switch(opt) {
|
||||
case 'h':
|
||||
print_usage(argv);
|
||||
@ -533,6 +541,9 @@ int main(int argc, char** argv) {
|
||||
case 'O':
|
||||
sort_order = optarg;
|
||||
break;
|
||||
case 'G':
|
||||
gtk_dark = "true";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -606,6 +617,11 @@ int main(int argc, char** argv) {
|
||||
color_path = strdup(color_str);
|
||||
}
|
||||
|
||||
//Check if --gtk-dark was specified
|
||||
if(gtk_dark == NULL) {
|
||||
gtk_dark = map_get(config, "gtk_dark");
|
||||
}
|
||||
|
||||
free(COLORS_LOCATION);
|
||||
|
||||
struct option_node* tmp;
|
||||
@ -720,6 +736,10 @@ int main(int argc, char** argv) {
|
||||
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
if(gtk_dark != NULL && strcmp(gtk_dark, "true") == 0) {
|
||||
g_object_set(gtk_settings_get_default(),
|
||||
"gtk-application-prefer-dark-theme", 1, NULL);
|
||||
}
|
||||
wofi_load_css(false);
|
||||
|
||||
wofi_init(config);
|
||||
|
Loading…
Reference in New Issue
Block a user