Skip to content

Commit acb1979

Browse files
committed
[Theme] Undo part of default theme changes, always pick build-in
1 parent 214a6e0 commit acb1979

File tree

8 files changed

+82
-31
lines changed

8 files changed

+82
-31
lines changed

Makefile.am

+11-4
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ theme_DATA=\
238238
themes/solarized_alternate.rasi\
239239
themes/fancy.rasi\
240240
themes/iggy.rasi\
241-
themes/iggy.jpg\
242-
themes/default.rasi
241+
themes/iggy.jpg
243242

244243
##
245244
# Extra DIST
@@ -257,6 +256,7 @@ EXTRA_DIST+=\
257256
script/get_git_rev.sh\
258257
$(theme_DATA)\
259258
doc/default_configuration.rasi\
259+
doc/default_theme.rasi\
260260
Changelog
261261
##
262262
# Indent
@@ -328,6 +328,7 @@ textbox_test_CFLAGS=\
328328
-I$(top_builddir)/lexer/\
329329
-I$(top_srcdir)/lexer/\
330330
-I$(top_srcdir)/config/\
331+
-I$(top_builddir)/resources/\
331332
-I$(top_builddir)/
332333

333334
textbox_test_LDADD=\
@@ -368,7 +369,8 @@ widget_test_SOURCES=\
368369
config/config.c\
369370
lexer/theme-parser.y\
370371
lexer/theme-lexer.l\
371-
test/widget-test.c
372+
test/widget-test.c\
373+
resources/resources.c
372374

373375
box_test_LDADD=$(textbox_test_LDADD)
374376
box_test_CFLAGS=$(textbox_test_CFLAGS)
@@ -384,6 +386,7 @@ box_test_SOURCES=\
384386
include/theme.h\
385387
include/css-colors.h\
386388
config/config.c\
389+
resources/resources.c\
387390
test/box-test.c
388391

389392
scrollbar_test_LDADD=$(textbox_test_LDADD)
@@ -400,7 +403,8 @@ scrollbar_test_SOURCES=\
400403
include/theme.h\
401404
include/css-colors.h\
402405
config/config.c\
403-
test/scrollbar-test.c
406+
test/scrollbar-test.c\
407+
resources/resources.c
404408

405409
textbox_test_SOURCES=\
406410
source/widgets/widget.c\
@@ -424,6 +428,7 @@ textbox_test_SOURCES=\
424428
include/xrmoptions.h\
425429
include/helper.h\
426430
include/helper-theme.h\
431+
resources/resources.c\
427432
test/textbox-test.c
428433

429434
if USE_CHECK
@@ -448,6 +453,7 @@ theme_parser_test_SOURCES=\
448453
source/rofi-types.c\
449454
include/rofi-types.h\
450455
source/css-colors.c\
456+
resources/resources.c\
451457
test/theme-parser-test.c
452458
endif
453459

@@ -481,6 +487,7 @@ helper_test_CFLAGS=\
481487
-I$(top_builddir)/lexer/\
482488
-I$(top_srcdir)/lexer/\
483489
-I$(top_srcdir)/config/\
490+
-I$(top_builddir)/resources/\
484491
-I$(top_builddir)/
485492

486493
helper_test_LDADD=\

doc/default_configuration.rasi

+2
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ configuration {
1414
directories-first: true;
1515
}
1616
}
17+
18+
@theme "default"
File renamed without changes.

lexer/theme-lexer.l

+37
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434

3535
%{
3636
#include "config.h"
37+
#include "resources.h"
3738
#include <stdio.h>
3839
#include <glib.h>
40+
#include <gio/gio.h>
3941
#include <helper.h>
4042
#include <math.h>
4143
#include <strings.h>
@@ -56,6 +58,8 @@ typedef enum {
5658
PT_FILE,
5759
/** Parse a string */
5860
PT_STRING,
61+
/** Parse a string */
62+
PT_STRING_ALLOC,
5963
/** Parse environment */
6064
PT_ENV
6165
} ParseType;
@@ -75,6 +79,8 @@ typedef struct _ParseObject {
7579
int str_len;
7680
/** String */
7781
const char *input_str;
82+
/** For where we need to free at end. (PT_STRING_ALLOC); */
83+
char *malloc_str;
7884
/** Position in file */
7985
YYLTYPE location;
8086
} ParseObject;
@@ -127,6 +133,7 @@ static double rofi_theme_parse_convert_hex ( char high, char low)
127133
break;\
128134
}\
129135
case PT_ENV:\
136+
case PT_STRING_ALLOC:\
130137
case PT_STRING:\
131138
{\
132139
yy_size_t len = MIN (max_size, current->str_len);\
@@ -273,6 +280,7 @@ C_COMMENT_OPEN "/*"
273280

274281
INCLUDE "@import"
275282
THEME "@theme"
283+
DEFAULT (?i:\"default\"?)
276284
277285
MEDIA "@media"
278286
@@ -363,6 +371,26 @@ if ( queue == NULL ) {
363371
<INCLUDE>{WHITESPACE} {}
364372
365373
/** Parse path. Last element in this INCLUDE */
374+
<INCLUDE>{DEFAULT} {
375+
yytext[yyleng-1] = '\0';
376+
/** Add Parse object */
377+
GBytes *theme_data = g_resource_lookup_data( resources_get_resource(),
378+
"/org/qtools/rofi/default.rasi", G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
379+
if (theme_data) {
380+
const char *theme = g_bytes_get_data(theme_data, NULL);
381+
file_queue = g_queue_new ();
382+
ParseObject *po = g_malloc0(sizeof(ParseObject));
383+
po->type = PT_STRING_ALLOC;
384+
po->malloc_str = g_strdup(theme);
385+
po->input_str = po->malloc_str;
386+
po->str_len = strlen(po->malloc_str);
387+
current = po;
388+
g_queue_push_head ( file_queue, po );
389+
g_bytes_unref(theme_data);
390+
}
391+
// Pop out of include. */
392+
BEGIN(GPOINTER_TO_INT(g_queue_pop_head ( queue )));
393+
}
366394
<INCLUDE>{STRING} {
367395
yytext[yyleng-1] = '\0';
368396
ParseObject *top = g_queue_peek_head ( file_queue );
@@ -666,6 +694,9 @@ if ( queue == NULL ) {
666694
if ( po->type == PT_FILE ) {
667695
fclose ( po->filein );
668696
}
697+
if ( po->type == PT_STRING_ALLOC ) {
698+
g_free( po->malloc_str);
699+
}
669700
g_free ( po );
670701
}
671702
po = g_queue_peek_head ( file_queue );
@@ -812,6 +843,9 @@ gboolean rofi_theme_parse_file ( const char *file )
812843
if ( po->type == PT_FILE ) {
813844
fclose ( po->filein );
814845
}
846+
if ( po->type == PT_STRING_ALLOC ) {
847+
g_free( po->malloc_str);
848+
}
815849
g_free ( po );
816850
}
817851
}
@@ -847,6 +881,9 @@ gboolean rofi_theme_parse_string ( const char *string )
847881
if ( po->type == PT_FILE ) {
848882
fclose ( po->filein );
849883
}
884+
if ( po->type == PT_STRING_ALLOC ) {
885+
g_free( po->malloc_str);
886+
}
850887
g_free ( po );
851888
}
852889
}

meson.build

+5-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ install_data(
266266
'themes/fancy.rasi',
267267
'themes/iggy.rasi',
268268
'themes/iggy.jpg',
269-
'themes/default.rasi',
270269
install_dir: themedir
271270
)
272271

@@ -312,6 +311,7 @@ test('widget test', executable('widget.test', [
312311
'test/widget-test.c',
313312
theme_parser,
314313
theme_lexer,
314+
default_theme,
315315
],
316316
objects: rofi.extract_objects([
317317
'source/widgets/widget.c',
@@ -329,6 +329,7 @@ test('box test', executable('box.test', [
329329
'test/box-test.c',
330330
theme_parser,
331331
theme_lexer,
332+
default_theme,
332333
],
333334
objects: rofi.extract_objects([
334335
'source/widgets/widget.c',
@@ -345,6 +346,7 @@ test('scrollbar test', executable('scrollbar.test', [
345346
'test/scrollbar-test.c',
346347
theme_parser,
347348
theme_lexer,
349+
default_theme,
348350
],
349351
objects: rofi.extract_objects([
350352
'source/widgets/widget.c',
@@ -361,6 +363,7 @@ test('textbox test', executable('textbox.test', [
361363
'test/textbox-test.c',
362364
theme_parser,
363365
theme_lexer,
366+
default_theme,
364367
],
365368
objects: rofi.extract_objects([
366369
'source/widgets/widget.c',
@@ -428,6 +431,7 @@ if check.found()
428431
'source/theme.c',
429432
'source/rofi-types.c',
430433
'source/css-colors.c',
434+
'resources/resources.c',
431435
]),
432436
dependencies: deps,
433437
))

releasenotes/1.7.0/release-1.7.0.markdown

+25
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ some of the more 'off-script' use of rofi.
1717
This release was made possible by many contributors, see below for a full list. Big thanks again to SardemFF7 and
1818
TonCherAmi.
1919

20+
21+
## Default theme loading
22+
23+
In older version of **rofi** the default theme was (almost) always loaded based on some unclear rules, sometimes
24+
some random patch code was loaded and sometimes no theme was loaded before loading another theme.
25+
26+
The current version of rofi this is hopefully more logic. It loads the default
27+
theme by default using the default configuration. (Can be disabled by `-no-default-config`).
28+
Using `-theme`, or `@theme` primitive will discard the theme completely.
29+
30+
So the below css completely removes the default theme, and loads `iggy`.
31+
32+
```css
33+
configuration {
34+
35+
36+
}
37+
38+
@theme "iggy"
39+
40+
element {
41+
children: [element-icon, element-text];
42+
}
43+
```
44+
2045
## File Browser
2146

2247
TonCherAmi made several very nice usability improvements to the file-browser. His changes allow you to define sorting

resources/resources.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<gresources>
33
<gresource prefix="/org/qtools/rofi">
4-
<file alias="default.rasi">themes/default.rasi</file>
4+
<file alias="default.rasi">doc/default_theme.rasi</file>
55
<file alias="default_configuration.rasi">doc/default_configuration.rasi</file>
66
</gresource>
77
</gresources>

source/rofi.c

+1-25
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ int main(int argc, char *argv[]) {
841841
"Pidfile location");
842842

843843
/** default configuration */
844-
{
844+
if (find_arg("-no-default-config") < 0) {
845845
GBytes *theme_data = g_resource_lookup_data(
846846
resources_get_resource(), "/org/qtools/rofi/default_configuration.rasi",
847847
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
@@ -987,30 +987,6 @@ int main(int argc, char *argv[]) {
987987
windowid = config.monitor;
988988
}
989989
}
990-
// Load default theme, if no theme was set and we don't have a current theme
991-
// loaded.
992-
if (config.theme == NULL && rofi_theme_is_empty()) {
993-
GBytes *theme_data = g_resource_lookup_data(
994-
resources_get_resource(), "/org/qtools/rofi/default.rasi",
995-
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
996-
if (theme_data) {
997-
const char *theme = g_bytes_get_data(theme_data, NULL);
998-
if (rofi_theme_parse_string((const char *)theme)) {
999-
g_warning("Failed to parse default theme. Giving up..");
1000-
if (list_of_error_msgs) {
1001-
for (GList *iter = g_list_first(list_of_error_msgs); iter != NULL;
1002-
iter = g_list_next(iter)) {
1003-
g_warning("Error: %s%s%s", color_bold, ((GString *)iter->data)->str,
1004-
color_reset);
1005-
}
1006-
}
1007-
rofi_theme = NULL;
1008-
cleanup();
1009-
return EXIT_FAILURE;
1010-
}
1011-
g_bytes_unref(theme_data);
1012-
}
1013-
}
1014990

1015991
/**
1016992
* Make small commandline changes to the current theme.

0 commit comments

Comments
 (0)