diff --git a/data/style.css b/data/style.css index 21455415..cd716cea 100644 --- a/data/style.css +++ b/data/style.css @@ -37,6 +37,12 @@ background: @theme_bg_color; } +.opaque-text text { + /* found by roaming through /usr/share/themes, + and some experimentation in the gnome inspector */ + color: alpha(currentColor, 0.5); +} + /* @theme_bg_color @theme_selected_bg_color diff --git a/inputremapper/gui/components/editor.py b/inputremapper/gui/components/editor.py index 502e1266..6823b04d 100644 --- a/inputremapper/gui/components/editor.py +++ b/inputremapper/gui/components/editor.py @@ -442,6 +442,7 @@ class CodeEditor: if self.code.strip().lower() == "": self.code = self.placeholder + self.gui.get_style_context().add_class("opaque-text") def _clear_placeholder(self, *_): if not self._shows_placeholder(): @@ -451,6 +452,8 @@ class CodeEditor: with HandlerDisabled(buffer, self._on_gtk_changed): buffer.set_text("") + self.gui.get_style_context().remove_class("opaque-text") + def _shows_placeholder(self): buffer = self.gui.get_buffer() code = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter(), True) diff --git a/tests/integration/test_components.py b/tests/integration/test_components.py index 84545227..84869de3 100644 --- a/tests/integration/test_components.py +++ b/tests/integration/test_components.py @@ -910,18 +910,22 @@ class TestCodeEditor(ComponentBaseTest): # clears the input when we enter the editor widget focus() self.assertEqual(self.get_text(), "") + self.assertNotIn("opaque-text", self.gui.get_style_context().list_classes()) # adds the placeholder back when we leave it unfocus() self.assertEqual(self.get_text(), self.editor.placeholder) + self.assertIn("opaque-text", self.gui.get_style_context().list_classes()) # if we enter text and then leave, it won't show the placeholder focus() self.assertEqual(self.get_text(), "") buffer = self.gui.get_buffer() buffer.set_text("foo") + self.assertNotIn("opaque-text", self.gui.get_style_context().list_classes()) unfocus() self.assertEqual(self.get_text(), "foo") + self.assertNotIn("opaque-text", self.gui.get_style_context().list_classes()) class TestRecordingToggle(ComponentBaseTest):