Skip to content

Commit

Permalink
Adding dark mode detection inside of OS Utils and macOS platform
Browse files Browse the repository at this point in the history
  • Loading branch information
justingeeslin committed Aug 4, 2020
1 parent adb9522 commit eb55c9a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions java/edu/cmu/cs/hcii/cogtool/util/Platform.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public interface PlatformMenuActions

public void setTheme(Display d);

public boolean isSystemDarkAppearance();

/**
* Bind the above callbacks to the Application Menu; only relevant
* for Macintosh, other platforms should ignore this.
Expand Down
5 changes: 5 additions & 0 deletions java/edu/cmu/cs/hcii/cogtool/util/PlatformAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ public void initTransferData(TransferData td)
{
// do nothing unless overriden
}

public boolean isSystemDarkAppearance() {
// Most OS do not have a dark mode at the time of this writing.
return false;
}
}
9 changes: 7 additions & 2 deletions mac-support/edu/cmu/cs/hcii/cogtool/util/MacOSXPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class MacOSXPlatform extends PlatformAdapter
public void setTheme(Display display) {
try {
// changing the appearance works only after the shell has been created
OS.setTheme(OS.isSystemDarkAppearance());
OS.setTheme(isSystemDarkAppearance());
// workaround for a bug in SWT: colors need to be reinited after changing the appearance
Method initColor = display.getClass().getDeclaredMethod("initColors");
initColor.setAccessible(true);
Expand All @@ -132,7 +132,12 @@ public void setTheme(Display display) {
catch (Exception e) {
e.printStackTrace();
}
}
}

@Override
public boolean isSystemDarkAppearance() {
return OS.isSystemDarkAppearance();
}

@Override
public void initPlatformMenu(Display display,
Expand Down

0 comments on commit eb55c9a

Please sign in to comment.