Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 27, 2020
2 parents f7d4511 + 8afa95b commit f03baa0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
22 changes: 16 additions & 6 deletions src/macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
default_TouchBarVariant,
};

static NSString *currentSystemAppearance_(void) {
/* This API does not exist on 10.13. */
@try {
return [[NSApp effectiveAppearance] name];
}
@catch (NSException *) {
return @"NSAppearanceNameAqua";
}
}

/*----------------------------------------------------------------------------------------------*/

@interface CommandButton : NSCustomTouchBarItem {
Expand Down Expand Up @@ -447,7 +457,11 @@ void setupApplication_MacOS(void) {
NSApplication *app = [NSApplication sharedApplication];
/* Our delegate will override SDL's delegate. */
MyDelegate *myDel = [[MyDelegate alloc] initWithSDLDelegate:app.delegate];
[myDel setAppearance:[[app effectiveAppearance] name]];
[myDel setAppearance:currentSystemAppearance_()];
[app addObserver:myDel
forKeyPath:@"effectiveAppearance"
options:0
context:myDel];
app.delegate = myDel;
NSMenu *appMenu = [[[NSApp mainMenu] itemAtIndex:0] submenu];
NSMenuItem *prefsItem = [appMenu itemWithTitle:@"Preferences…"];
Expand All @@ -463,10 +477,6 @@ void setupApplication_MacOS(void) {
void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) {
NSApplication *app = [NSApplication sharedApplication];
MyDelegate *myDel = (MyDelegate *) app.delegate;
[app addObserver:myDel
forKeyPath:@"effectiveAppearance"
options:0
context:myDel];
NSMenu *appMenu = [app mainMenu];
NSMenuItem *mainItem = [appMenu insertItemWithTitle:[NSString stringWithUTF8String:menuLabel]
action:nil
Expand Down Expand Up @@ -525,7 +535,7 @@ void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *
void handleCommand_MacOS(const char *cmd) {
if (equal_Command(cmd, "prefs.ostheme.changed")) {
if (arg_Command(cmd)) {
appearanceChanged_MacOS_([[NSApp effectiveAppearance] name]);
appearanceChanged_MacOS_(currentSystemAppearance_());
}
}
#if 0
Expand Down
10 changes: 7 additions & 3 deletions src/ui/documentwidget.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ static void animate_DocumentWidget_(void *ticker) {
}
}

static void updateSideOpacity_DocumentWidget_(iDocumentWidget *d) {
static void updateSideOpacity_DocumentWidget_(iDocumentWidget *d, iBool isAnimated) {
float opacity = 0.0f;
const iGmRun *banner = siteBanner_GmDocument(d->doc);
if (banner && bottom_Rect(banner->visBounds) < d->scrollY) {
opacity = 1.0f;
}
setValue_Anim(&d->sideOpacity, opacity, opacity < 0.5f ? 100 : 200);
setValue_Anim(&d->sideOpacity, opacity, isAnimated ? (opacity < 0.5f ? 100 : 200) : 0);
animate_DocumentWidget_(d);
}

Expand Down Expand Up @@ -445,7 +445,7 @@ static void updateVisible_DocumentWidget_(iDocumentWidget *d) {
d->firstVisibleRun = NULL;
render_GmDocument(d->doc, visRange, addVisibleLink_DocumentWidget_, d);
updateHover_DocumentWidget_(d, mouseCoord_Window(get_Window()));
updateSideOpacity_DocumentWidget_(d);
updateSideOpacity_DocumentWidget_(d, iTrue);
/* Remember scroll positions of recently visited pages. */ {
iRecentUrl *recent = mostRecentUrl_History(d->mod.history);
if (recent && docSize && d->state == ready_RequestState) {
Expand Down Expand Up @@ -852,6 +852,7 @@ static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) {
updateDocument_DocumentWidget_(d, resp);
d->scrollY = d->initNormScrollY * size_GmDocument(d->doc).y;
d->state = ready_RequestState;
updateSideOpacity_DocumentWidget_(d, iFalse);
updateOutline_DocumentWidget_(d);
updateVisible_DocumentWidget_(d);
postCommandf_App("document.changed doc:%p url:%s", d, cstr_String(d->mod.url));
Expand Down Expand Up @@ -984,6 +985,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
if (d->state == fetching_RequestState) {
d->state = receivedPartialResponse_RequestState;
updateTrust_DocumentWidget_(d, response_GmRequest(d->request));
init_Anim(&d->sideOpacity, 0);
switch (category_GmStatusCode(statusCode)) {
case categoryInput_GmStatusCode: {
iUrl parts;
Expand Down Expand Up @@ -1213,6 +1215,8 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
updateSize_DocumentWidget(d);
updateFetchProgress_DocumentWidget_(d);
}
init_Anim(&d->sideOpacity, 0);
updateSideOpacity_DocumentWidget_(d, iFalse);
updateOutlineOpacity_DocumentWidget_(d);
updateWindowTitle_DocumentWidget_(d);
allocVisBuffer_DocumentWidget_(d);
Expand Down

0 comments on commit f03baa0

Please sign in to comment.