Skip to content

Adds macOS theme switch listening#430

Draft
0verEngineer wants to merge 13 commits into
Murmele:masterfrom
0verEngineer:mac_theme_switch_listener
Draft

Adds macOS theme switch listening#430
0verEngineer wants to merge 13 commits into
Murmele:masterfrom
0verEngineer:mac_theme_switch_listener

Conversation

@0verEngineer

Copy link
Copy Markdown

Comment thread src/ui/MainWindow.cpp Outdated
}

void MainWindow::changeEvent(QEvent *e) {
#ifdef Q_OS_MACX

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a headsup, there are tools that replicate this macOS function on Windows etc.

(I don’t know QT, so not sure if this triggers the same event or if it even supports it, so feel free to disregard this.)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes maybe we can use it also for windows and linux

Comment thread src/ui/MainWindow.cpp Outdated
@Murmele

Murmele commented Jan 20, 2023

Copy link
Copy Markdown
Owner

@0verEngineer thanks for the work and @LenaWil thanks for the review!

@0verEngineer can you remove the ifdef for testing. Then we are getting builds for windows, linux and macos and we can test it easily.

@LenaWil did it work for you?

@0verEngineer

Copy link
Copy Markdown
Author

@Murmele I have removed the ifdefs and i also tested the event thing on Gnome but no event is fired on theme neither lagacy theme switch.

@0verEngineer

Copy link
Copy Markdown
Author

Checked KDE and Windows Theme change in Settings:

KDE:
ThemeChange and StyleChange event triggered

Windows:
ThemeChange, StyleChange and PaletteChange events triggered multiple times

If we reload the theme on each of the 3 Events it will be done multiple times in a row, idk how this works performance wise, i think we should reload on Windows and KDE only on the ThemeChange event and on MacOS like it is now.

I will do it later :)

@LenaWil

LenaWil commented Jan 20, 2023

Copy link
Copy Markdown

@LenaWil did it work for you?

I haven’t actually set up a build-environment currently, before I do that, is there a way to easily downloaded a pre-built version?

@Murmele

Murmele commented Jan 21, 2023

Copy link
Copy Markdown
Owner

@LenaWil did it work for you?

I haven’t actually set up a build-environment currently, before I do that, is there a way to easily downloaded a pre-built version?

Yes, just check the build artifacts. There you can find a macos build.

https://github.com/Murmele/Gittyup/actions/runs/3970480332

image

image

@Murmele

Murmele commented Jan 21, 2023

Copy link
Copy Markdown
Owner

Checked KDE and Windows Theme change in Settings:

KDE: ThemeChange and StyleChange event triggered

Windows: ThemeChange, StyleChange and PaletteChange events triggered multiple times

If we reload the theme on each of the 3 Events it will be done multiple times in a row, idk how this works performance wise, i think we should reload on Windows and KDE only on the ThemeChange event and on MacOS like it is now.

I will do it later :)

Thanks for testing. Would be nice if we can fix it on all three OS.

@LenaWil

LenaWil commented Jan 21, 2023

Copy link
Copy Markdown

@LenaWil did it work for you?

Okay definitely better than first, the only thing is that the code preview doesn’t update properly and still has the dark/light theme after switching to the opposite. But I can at least read the code now!

Light theme after switching
Dark theme after switching

@Murmele

Murmele commented Jan 21, 2023

Copy link
Copy Markdown
Owner

great! Something for scintilla is missing

@Murmele

Murmele commented Jan 21, 2023

Copy link
Copy Markdown
Owner

Maybe we have to implement the event also for the texteditor

TextEditor::TextEditor(QWidget *parent) : ScintillaIFace(parent) {
  // Load colors.
  Theme *theme = Application::theme();
  mOursColor = theme->diff(Theme::Diff::Ours);
  mTheirsColor = theme->diff(Theme::Diff::Theirs);
  mAdditionColor = theme->diff(Theme::Diff::Addition);
  mDeletionColor = theme->diff(Theme::Diff::Deletion);

There are more theme related things below

// Set word diff indicators.
  indicSetStyle(WordAddition, INDIC_STRAIGHTBOX);
  indicSetFore(WordAddition, theme->diff(Theme::Diff::WordAddition));
  indicSetAlpha(WordAddition, 255);
  indicSetUnder(WordAddition, true);

  indicSetStyle(WordDeletion, INDIC_STRAIGHTBOX);
  indicSetFore(WordDeletion, theme->diff(Theme::Diff::WordDeletion));
  indicSetAlpha(WordDeletion, 255);
  indicSetUnder(WordDeletion, true);

  indicSetStyle(NoteIndicator, INDIC_SQUIGGLE);
  indicSetFore(NoteIndicator, theme->diff(Theme::Diff::Note));
  indicSetAlpha(NoteIndicator, 255);
  indicSetUnder(NoteIndicator, true);

  indicSetStyle(WarningIndicator, INDIC_STRAIGHTBOX);
  indicSetFore(WarningIndicator, theme->diff(Theme::Diff::Warning));
  indicSetAlpha(WarningIndicator, 255);
  indicSetUnder(WarningIndicator, true);

  indicSetStyle(ErrorIndicator, INDIC_STRAIGHTBOX);
  indicSetFore(ErrorIndicator, theme->diff(Theme::Diff::Error));
  indicSetAlpha(ErrorIndicator, 255);
  indicSetUnder(ErrorIndicator, true);

  // Initialize LPeg lexer.
  QColor base = palette().color(QPalette::Base);
  QColor text = palette().color(QPalette::Text);
  bool dark = (text.lightnessF() > base.lightnessF());

  setLexerLanguage("lpeg");
  setProperty("lexer.lpeg.home", Settings::lexerDir().path());
  setProperty("lexer.lpeg.themes", theme->dir().path());
  setProperty("lexer.lpeg.theme", theme->name());
  setProperty("lexer.lpeg.theme.mode", dark ? "dark" : "light");

moving all related code to the end of the constructor if this is working in own function which will be called also for those events

@Murmele Murmele self-requested a review January 22, 2023 10:30
@Murmele Murmele added this to the Next release milestone Jan 23, 2023
@0verEngineer

Copy link
Copy Markdown
Author

Maybe we have to implement the event also for the texteditor

TextEditor::TextEditor(QWidget *parent) : ScintillaIFace(parent) {
  // Load colors.
  Theme *theme = Application::theme();
  mOursColor = theme->diff(Theme::Diff::Ours);
  mTheirsColor = theme->diff(Theme::Diff::Theirs);
  mAdditionColor = theme->diff(Theme::Diff::Addition);
  mDeletionColor = theme->diff(Theme::Diff::Deletion);

There are more theme related things below

// Set word diff indicators.
  indicSetStyle(WordAddition, INDIC_STRAIGHTBOX);
  indicSetFore(WordAddition, theme->diff(Theme::Diff::WordAddition));
  indicSetAlpha(WordAddition, 255);
  indicSetUnder(WordAddition, true);

  indicSetStyle(WordDeletion, INDIC_STRAIGHTBOX);
  indicSetFore(WordDeletion, theme->diff(Theme::Diff::WordDeletion));
  indicSetAlpha(WordDeletion, 255);
  indicSetUnder(WordDeletion, true);

  indicSetStyle(NoteIndicator, INDIC_SQUIGGLE);
  indicSetFore(NoteIndicator, theme->diff(Theme::Diff::Note));
  indicSetAlpha(NoteIndicator, 255);
  indicSetUnder(NoteIndicator, true);

  indicSetStyle(WarningIndicator, INDIC_STRAIGHTBOX);
  indicSetFore(WarningIndicator, theme->diff(Theme::Diff::Warning));
  indicSetAlpha(WarningIndicator, 255);
  indicSetUnder(WarningIndicator, true);

  indicSetStyle(ErrorIndicator, INDIC_STRAIGHTBOX);
  indicSetFore(ErrorIndicator, theme->diff(Theme::Diff::Error));
  indicSetAlpha(ErrorIndicator, 255);
  indicSetUnder(ErrorIndicator, true);

  // Initialize LPeg lexer.
  QColor base = palette().color(QPalette::Base);
  QColor text = palette().color(QPalette::Text);
  bool dark = (text.lightnessF() > base.lightnessF());

  setLexerLanguage("lpeg");
  setProperty("lexer.lpeg.home", Settings::lexerDir().path());
  setProperty("lexer.lpeg.themes", theme->dir().path());
  setProperty("lexer.lpeg.theme", theme->name());
  setProperty("lexer.lpeg.theme.mode", dark ? "dark" : "light");

moving all related code to the end of the constructor if this is working in own function which will be called also for those events

@Murmele The changeEvent is not called on the TextEditors so i have added a static list that holds all instances in order to refresh the theme, but if i call all that theme related stuff inside its own function only the text color is changed, the background and highlight colors stay the same. I don't know Scintilla at all so i have no idea how to implement this atm.

@Murmele

Murmele commented Jan 26, 2023

Copy link
Copy Markdown
Owner

I will have a look next days

@exactly-one-kas exactly-one-kas added the enhancement New feature or request label Jan 27, 2023
@Murmele Murmele marked this pull request as draft January 27, 2023 11:33
@Murmele

Murmele commented Jan 27, 2023

Copy link
Copy Markdown
Owner

@0verEngineer can you enable that I have write permission to your branch? Otherwise I cannot push changes (If I remember me correctly you can do it here in this PR on the right side somewhere)

@0verEngineer

Copy link
Copy Markdown
Author

@Murmele It is already enabled and i have nothing changed after creating the fork
Screenshot from 2023-01-27 14-27-21

@Murmele

Murmele commented Jan 27, 2023

Copy link
Copy Markdown
Owner

ah sorry was on the _test branch and not on the one from this PR. I am not able to get the changeEvent triggered with windows 10, I am trying later on linux.

@0verEngineer

Copy link
Copy Markdown
Author

ah sorry was on the _test branch and not on the one from this PR. I am not able to get the changeEvent triggered with windows 10, I am trying later on linux.

Ahh this is my fault, i did the testing if the events are triggered with qt 6.2...

It is not triggered on KDE either.

@Murmele

Murmele commented Jan 27, 2023

Copy link
Copy Markdown
Owner

From here:

Currently there seems to be no way to conect to a signal or event that shows the theme has changed in Windows. So I connected to a signal from a QTimer that fires every 5 seconds to check windowsIsInDarkTheme().

Instead of this workaround I would let it be for all systems which do not support it and once we are going with Qt6 it is working automatically.
@0verEngineer can you try my changes? Still we have to find a way to get rid of this TextEdit list. I don't like it ^^

@0verEngineer

Copy link
Copy Markdown
Author

@Murmele I also don't like the TextEdit list :D

I have just tested your changes but it does not change anything about the TextEditor and i also found 2 problems in the normal theming

Screenshot 2023-01-27 at 16 59 56

@Murmele

Murmele commented Feb 9, 2023

Copy link
Copy Markdown
Owner

@Murmele I also don't like the TextEdit list :D

I have just tested your changes but it does not change anything about the TextEditor and i also found 2 problems in the normal theming

Screenshot 2023-01-27 at 16 59 56

@0verEngineer Sorry for comming back that late. This problem does not exist on Windows and I never realized it on Linux so I assume it is also not there. The problem is, that I was currently not able to get the switching reproducable. I have to check how to get the switching work

@0verEngineer

Copy link
Copy Markdown
Author

@Murmele Is MainWindow::changeEvent also not called on Windows?
If not then we should just delay this stuff until Gittyup is migrated to qt6 where the changeEvent works.

@Murmele

Murmele commented Feb 11, 2023

Copy link
Copy Markdown
Owner

No I did not see. I think if you get it work completely for macos this is fine for me and we can merge it. Once we found a solution on windows / linux we are changing it or it might be resolved automatically with qt6.

@LenaWil

LenaWil commented Mar 2, 2023

Copy link
Copy Markdown

No I did not see. I think if you get it work completely for macos this is fine for me and we can merge it. Once we found a solution on windows / linux we are changing it or it might be resolved automatically with qt6.

Yeah, I agree, I commented because I thought it might be really easy to also implement it, but if that’s not the case, it might be best to focus on macOS.

@0verEngineer

Copy link
Copy Markdown
Author

I will try to fix the missing stuff for the branch selector and the scintilla stuff this or next weekend, but i have no idea how scintilla works.

Is there an active contributor who has scintilla knowledge that i can contact if i'm stuck? @Murmele

@Murmele

Murmele commented Mar 2, 2023

Copy link
Copy Markdown
Owner

Hi @0verEngineer I don't have that much experience in it. Next two weeks I am quite busy, but then maybe I can give a try

@Murmele

Murmele commented Apr 30, 2023

Copy link
Copy Markdown
Owner

I will check if we can switch to Qt6 and hopefully then this is working then as well

@LenaWil

LenaWil commented Sep 14, 2023

Copy link
Copy Markdown

Any updates?

@Murmele

Murmele commented Oct 8, 2023

Copy link
Copy Markdown
Owner

Any updates?

I am working on a Qt6 build now. Once it is finished, this can be rebased on it. Then we can check it again

@Murmele

Murmele commented Oct 27, 2023

Copy link
Copy Markdown
Owner

Is there anybody which can fix the build error in my Qt6 branch?
#429

@Murmele

Murmele commented Feb 6, 2024

Copy link
Copy Markdown
Owner

Can you try to rebase this one on top of the Qt6 branch to see if it works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants