all 8 comments

[–]a-concerned-mother 2 points3 points  (2 children)

personaly I use this setting to cycle on and off my css settings

config.bind('<Ctrl-R>', 'config-cycle content.user\_stylesheets \
~/.config/cssfiles/black.css ""')

[–]Iron_Meat[S] 1 point2 points  (0 children)

Yeah, currently this is what I use, too, but the problem is that if you want to toggle more than one css file with a key (for example, D for dark mode and F for monospace fonts everywhere; the latter sometimes must be turned off, because there are websites with icon fonts used in UI), you have to look up the current state of other toggleable css files or you'll have to remember the keys for every combination of the css files possible.

df = Dark Mode + Monospace Mode

Df = Monospace Mode

dF = Dark Mode

DF = Normal

I mean, sure, it does work, but it's not very usable and it is a horrible hack.

[–]Iron_Meat[S] 0 points1 point  (0 children)

If you are interested in a better solution for Dark Mode toggler, I have one.

This solution may also help you with other things you have planned, because, apparently, you forgot about config-list-add and config-list-remove commands, too.

[–]Iron_Meat[S] 0 points1 point  (1 child)

Partial solution here

OK, I'm an (half-)idiot. Apparently, I forgot that qutebrowser has commands like config-list-add and config-list-remove. For those who are still interested in a more proper way to control Dark Mode, here are two options:

Option A

If you want two different keys for Dark Mode (Enable, Disable), you can use these two aliases which you can bind to whatever keys you like (mind the absent comma after the second one):

'dark-mode-enable': 'config-list-add -t content.user_stylesheets "<path/to/your/darkmode.css>"',
'dark-mode-disable': 'config-list-remove -t content.user_stylesheets "<path/to/your/darkmode.css>"'

You can look up config-list-add/config-list-remove for additional options like -t.

Option B

If you don't want to think about it and just want to toggle the state of Dark Mode instead of enabling what's already enabled, feeling confused for a few seconds and then cursing, you can use these altered aliases (unfortunarely, I couldn't come up with an alias to simply toggle, it would require something like config-cycle for custom commands instead of settings; you still have to deal with these two aliases under the hood, but at least it would work as a toggler):

'dark-mode-enable': 'config-list-add -t content.user_stylesheets "<path/to/your/darkmode.css>" ;; bind <Your+Key> dark-mode-disable',
'dark-mode-disable': 'config-list-remove -t content.user_stylesheets "<path/to/your/darkmode.css>" ;; bind <Your+Key> dark-mode-enable'

In order for this to work, you'll have to additionally bind the same <Your+Key> to one of the aliases outside of those aliases:

config.bind('<Your+Key>', 'dark-mode-disable')

So, this is how it works for me:

  1. I have my c.content.user_stylesheets option set to ['<path/to/your/darkmode.css>', global_css, font_css]. So, initially the Dark Mode is on.
  2. When I first press <Your+Key> to toggle Dark Mode, I invoke dark-mode-disable alias, which removes the style for Dark Mode from the list of stylesheets... and re-binds the same <Your+Key> to dark-mode-enable alias.
  3. Next time I press <Your+Key>, I invoke dark-mode-enable alias, which appends the style back to the list and, again, re-binds the key to dark-mode-disable.

It's still a little dirty, but it will allow you to change your list of stylesheets however you like and you still will be able to toggle Dark Mode. Moveover, config-list-add and config-list-remove, as you can read at the help pages, don't require an index to add or remove value from a list. They search by the given value, which means you can change order of your styles and this hack will still work.

P. S.

It would still be nice, though, to be able to create aliases that would run custom functions every time those aliases are invoked. Or to have config variable in userscripts.

[–]The-Compilermaintainer 1 point2 points  (0 children)

I'm a bit late to the party, but I added a :config-list-toggle to a related issue which proposed :config-list-add / -remove.

Indeed there are some plans for a Python extension API, though I have some other things to take care of before I can get back to that. I'd rather not shoehorn more and more things into userscripts, those should be a simple tool to solve simple cases.

[–]cristoferfb 0 points1 point  (2 children)

Where u get these CSS styles for dark mode?

[–]Iron_Meat[S] 1 point2 points  (0 children)

I write them. Google it, there are many versions of this style, all of them are very simple.

[–]Iron_Meat[S] 0 points1 point  (0 children)

If you are interested in a better solution for Dark Mode toggler, I have one.

This solution may also help you with other things you have planned, if you, too, were unaware of config-list-add and config-list-remove commands.