Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
# Conflicts:
#	CMakeLists.txt
#	res/about/version.gmi
#	src/ui/documentwidget.c
  • Loading branch information
skyjake committed Nov 16, 2020
2 parents 22abc53 + b1574e7 commit 6e1e7d0
Show file tree
Hide file tree
Showing 22 changed files with 280 additions and 87 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
cmake_minimum_required (VERSION 3.9)

project (Lagrange
VERSION 0.8.1
VERSION 0.9.0
DESCRIPTION "A Beautiful Gemini Client"
LANGUAGES C
)
Expand Down Expand Up @@ -279,7 +279,7 @@ Exec=${CMAKE_INSTALL_PREFIX}/bin/lagrange %U
Terminal=false
Type=Application
Icon=fi.skyjake.lagrange
MimeType=x-scheme-handler/gemini;
MimeType=x-scheme-handler/gemini;x-scheme-handler/gopher
")
install (TARGETS app DESTINATION bin)
install (FILES ${desktop} DESTINATION share/applications)
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ Once you have compiled a working binary under MSYS2, there is still an additiona

### Compiling on Raspberry Pi

You should use a version of SDL that is compiled to take advantage of the Broadcom VideoCore OpenGL ES hardware. This provides the best performance when running Lagrange in a console.
On Raspberry Pi 4/400, you can compile and run Lagrange just like on a regular desktop PC. Accelerated OpenGL graphics should work fine under X11.

At present time, OpenGL under X11 on Raspberry Pi is still quite slow/experimental. When running under X11, software rendering is the best choice and the SDL from Raspbian etc. is sufficient.
On Raspberry Pi 3 or earlier, you should use a version of SDL that is compiled to take advantage of the Broadcom VideoCore OpenGL ES hardware. This provides the best performance when running Lagrange in a console. OpenGL under X11 on Raspberry Pi 2/3 is quite
slow/experimental. When running under X11, software rendering is the best choice and the SDL from Raspbian etc. is sufficient.

The following build options are recommended on Raspberry Pi:
The following build options are recommended on Raspberry Pi 2/3:

* `ENABLE_KERNING=NO`: faster text rendering without noticeable loss of quality
* `ENABLE_WINDOWPOS_FIX=YES`: workaround for window position restore issues (SDL bug)
Expand Down
13 changes: 13 additions & 0 deletions res/about/version.gmi
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
```
# Release notes

## 0.9
* Clicking on the top banner of a page (where the site icon and hostname are shown) navigates to the root directory of the site.
* Added menu items and keybindings for navigating to site root or the parent directory.
* Added option to use a monospace body text font on all Gemini and/or Gopher pages.
* Remember redirect source URLs as visited but not shown in the History tab. Note that "visited.txt" is no longer fully compatible if opened in an older version of Lagrange.
* "gopher:" scheme is allowed in command line arguments.
* XDG: .desktop file declares support for opening Gopher URLs.
* Fixed an issue where copying the URL input field would not place anything on the clipboard.
* Fixed the Lagrange window visibly changing position during launch.
* Fixed crash when a single percent sign was typed in an input field.
* macOS: Fixed native menu keyboard shortcuts causing redundant command activations.
* macOS: Fixed assigning keybindings when there is an equivalent native menu shortcut.

## 0.8.1
* Fixed potential lockup when navigating back to a query prompt.
* macOS: Improved handling of scroll wheel events from a mouse.
Expand Down
30 changes: 27 additions & 3 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ static iString *serializePrefs_App_(const iApp *d) {
appendFormat_String(str, "prefs.dialogtab arg:%d\n", d->prefs.dialogTab);
appendFormat_String(str, "font.set arg:%d\n", d->prefs.font);
appendFormat_String(str, "headingfont.set arg:%d\n", d->prefs.headingFont);
appendFormat_String(str, "prefs.mono.gemini.changed arg:%d\n", d->prefs.monospaceGemini);
appendFormat_String(str, "prefs.mono.gopher.changed arg:%d\n", d->prefs.monospaceGopher);
appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent);
appendFormat_String(str, "smoothscroll arg:%d\n", d->prefs.smoothScrolling);
appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth);
Expand Down Expand Up @@ -415,8 +417,9 @@ static void init_App_(iApp *d, int argc, char **argv) {
for (size_t i = 1; i < size_StringList(args_CommandLine(&d->args)); i++) {
const iString *arg = constAt_StringList(args_CommandLine(&d->args), i);
const iBool isKnownScheme =
startsWithCase_String(arg, "gemini:") || startsWithCase_String(arg, "file:") ||
startsWithCase_String(arg, "data:") || startsWithCase_String(arg, "about:");
startsWithCase_String(arg, "gemini:") || startsWithCase_String(arg, "gopher:") ||
startsWithCase_String(arg, "file:") || startsWithCase_String(arg, "data:") ||
startsWithCase_String(arg, "about:");
if (isKnownScheme || fileExists_FileInfo(arg)) {
postCommandf_App("open newtab:%d url:%s",
newTab,
Expand Down Expand Up @@ -723,7 +726,7 @@ static void updateColorThemeButton_(iLabelWidget *button, int theme) {
iForEach(ObjectList, i, children_Widget(findChild_Widget(as_Widget(button), "menu"))) {
iLabelWidget *item = i.object;
if (!cmp_String(command_LabelWidget(item), command)) {
updateText_LabelWidget(button, label_LabelWidget(item));
updateText_LabelWidget(button, text_LabelWidget(item));
break;
}
}
Expand Down Expand Up @@ -986,6 +989,21 @@ iBool handleCommand_App(const char *cmd) {
postCommand_App("document.layout.changed");
return iTrue;
}
else if (equal_Command(cmd, "prefs.mono.gemini.changed") ||
equal_Command(cmd, "prefs.mono.gopher.changed")) {
const iBool isSet = (arg_Command(cmd) != 0);
setFreezeDraw_Window(d->window, iTrue);
if (startsWith_CStr(cmd, "prefs.mono.gemini")) {
d->prefs.monospaceGemini = isSet;
}
else {
d->prefs.monospaceGopher = isSet;
}
resetFonts_Text(); /* clear the glyph cache */
postCommand_App("font.changed");
postCommand_App("window.unfreeze");
return iTrue;
}
else if (equal_Command(cmd, "prefs.biglede.changed")) {
d->prefs.bigFirstParagraph = arg_Command(cmd) != 0;
postCommand_App("document.layout.changed");
Expand Down Expand Up @@ -1136,6 +1154,12 @@ iBool handleCommand_App(const char *cmd) {
findChild_Widget(dlg, format_CStr("prefs.headingfont.%d", d->prefs.headingFont)),
selected_WidgetFlag,
iTrue);
setFlags_Widget(findChild_Widget(dlg, "prefs.mono.gemini"),
selected_WidgetFlag,
d->prefs.monospaceGemini);
setFlags_Widget(findChild_Widget(dlg, "prefs.mono.gopher"),
selected_WidgetFlag,
d->prefs.monospaceGopher);
setFlags_Widget(
findChild_Widget(dlg, format_CStr("prefs.linewidth.%d", d->prefs.lineWidth)),
selected_WidgetFlag,
Expand Down
38 changes: 22 additions & 16 deletions src/gmdocument.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,24 +235,29 @@ static void clearLinks_GmDocument_(iGmDocument *d) {
clear_PtrArray(&d->links);
}

#if 0
static iBool isGopher_GmDocument_(const iGmDocument *d) {
return equalCase_Rangecc(urlScheme_String(&d->url), "gopher");
static iBool isForcedMonospace_GmDocument_(const iGmDocument *d) {
const iRangecc scheme = urlScheme_String(&d->url);
if (equalCase_Rangecc(scheme, "gemini")) {
return prefs_App()->monospaceGemini;
}
if (equalCase_Rangecc(scheme, "gopher")) {
return prefs_App()->monospaceGopher;
}
return iFalse;
}
#endif

static void doLayout_GmDocument_(iGmDocument *d) {
const iBool isGemini = iTrue; // !isGopher_GmDocument_(d);
const iBool isMono = isForcedMonospace_GmDocument_(d);
/* TODO: Collect these parameters into a GmTheme. */
const int fonts[max_GmLineType] = {
isGemini ? paragraph_FontId : preformatted_FontId,
isGemini ? paragraph_FontId : preformatted_FontId, /* bullet */
isMono ? regularMonospace_FontId : paragraph_FontId,
isMono ? regularMonospace_FontId : paragraph_FontId, /* bullet */
preformatted_FontId,
quote_FontId,
isGemini ? heading1_FontId : preformatted_FontId,
isGemini ? heading2_FontId : preformatted_FontId,
isGemini ? heading3_FontId : preformatted_FontId,
regular_FontId,
isMono ? regularMonospace_FontId : quote_FontId,
heading1_FontId,
heading2_FontId,
heading3_FontId,
isMono ? regularMonospace_FontId : regular_FontId,
};
static const int colors[max_GmLineType] = {
tmParagraph_ColorId,
Expand Down Expand Up @@ -292,7 +297,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
const iRangecc content = range_String(&d->source);
iRangecc contentLine = iNullRange;
iInt2 pos = zero_I2();
iBool isFirstText = isGemini && prefs->bigFirstParagraph;
iBool isFirstText = prefs->bigFirstParagraph;
iBool addQuoteIcon = prefs->quoteIcon;
iBool isPreformat = iFalse;
iRangecc preAltText = iNullRange;
Expand Down Expand Up @@ -363,7 +368,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
addSiteBanner = iFalse; /* overrides the banner */
continue;
}
run.font = preFont;
run.font = (d->format == plainText_GmDocumentFormat ? regularMonospace_FontId : preFont);
indent = indents[type];
}
if (addSiteBanner) {
Expand Down Expand Up @@ -463,6 +468,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
: link->flags & mailto_GmLinkFlag
? envelope
: link->flags & remote_GmLinkFlag ? globe : arrow);
icon.font = regular_FontId;
if (link->flags & remote_GmLinkFlag) {
icon.visBounds.pos.x -= gap_Text / 2;
}
Expand All @@ -477,7 +483,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
/* Special formatting for the first paragraph (e.g., subtitle, introduction, or lede). */
int bigCount = 0;
if (type == text_GmLineType && isFirstText) {
run.font = firstParagraph_FontId;
if (!isMono) run.font = firstParagraph_FontId;
run.color = tmFirstParagraph_ColorId;
bigCount = 15; /* max lines -- what if the whole document is one paragraph? */
isFirstText = iFalse;
Expand Down Expand Up @@ -520,7 +526,7 @@ static void doLayout_GmDocument_(iGmDocument *d) {
trimStart_Rangecc(&runLine);
pos.y += lineHeight_Text(run.font);
if (--bigCount == 0) {
run.font = paragraph_FontId;
run.font = fonts[text_GmLineType];
run.color = colors[text_GmLineType];
}
}
Expand Down
1 change: 1 addition & 0 deletions src/macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ void enableMomentumScroll_MacOS (void);
void registerURLHandler_MacOS (void);
void setupApplication_MacOS (void);
void insertMenuItems_MacOS (const char *menuLabel, int atIndex, const iMenuItem *items, size_t count);
void enableMenu_MacOS (const char *menuLabel, iBool enable);
void handleCommand_MacOS (const char *cmd);
25 changes: 23 additions & 2 deletions src/macos.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include "ui/command.h"
#include "ui/widget.h"
#include "ui/color.h"
#include "ui/window.h"

#include <SDL_timer.h>

#import <AppKit/AppKit.h>

Expand Down Expand Up @@ -217,7 +220,6 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}
}

#if 1
- (NSTouchBar *)makeTouchBar {
NSTouchBar *bar = [[NSTouchBar alloc] init];
bar.delegate = self;
Expand All @@ -235,7 +237,6 @@ - (NSTouchBar *)makeTouchBar {
}
return bar;
}
#endif

- (void)showPreferences {
postCommand_App("preferences");
Expand All @@ -249,6 +250,11 @@ - (void)postMenuItemCommand:(id)sender {
NSString *command = [menuCommands objectForKey:[(NSMenuItem *)sender title]];
if (command) {
postCommand_App([command cStringUsingEncoding:NSUTF8StringEncoding]);
/* Shouldn't double-activate menu items in case the same key is used in our widgets.
SDL ignores menu key equivalents so the keydown events will be posted regardless.
This is quite a kludge, but we can achieve this by taking advantage of Window's
focus-acquisition threshold for ignoring key events. */
get_Window()->focusGainedAt = SDL_GetTicks();
}
}

Expand Down Expand Up @@ -485,6 +491,15 @@ void setupApplication_MacOS(void) {
windowCloseItem.action = @selector(closeTab);
}

void enableMenu_MacOS(const char *menuLabel, iBool enable) {
NSApplication *app = [NSApplication sharedApplication];
NSMenu *appMenu = [app mainMenu];
NSString *label = [NSString stringWithUTF8String:menuLabel];
NSMenuItem *menuItem = [appMenu itemAtIndex:[appMenu indexOfItemWithTitle:label]];
[menuItem setEnabled:enable];
[label release];
}

void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) {
NSApplication *app = [NSApplication sharedApplication];
MyDelegate *myDel = (MyDelegate *) app.delegate;
Expand Down Expand Up @@ -513,6 +528,12 @@ void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *
else if (items[i].key == SDLK_RIGHT) {
appendChar_String(&key, 0x2192);
}
else if (items[i].key == SDLK_UP) {
appendChar_String(&key, 0x2191);
}
else if (items[i].key == SDLK_DOWN) {
appendChar_String(&key, 0x2193);
}
else if (items[i].key) {
appendChar_String(&key, items[i].key);
}
Expand Down
2 changes: 2 additions & 0 deletions src/prefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void init_Prefs(iPrefs *d) {
d->quoteIcon = iTrue;
d->font = nunito_TextFont;
d->headingFont = nunito_TextFont;
d->monospaceGemini = iFalse;
d->monospaceGopher = iFalse;
d->lineWidth = 40;
d->bigFirstParagraph = iTrue;
d->sideIcon = iTrue;
Expand Down
2 changes: 2 additions & 0 deletions src/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ struct Impl_Prefs {
/* Content */
enum iTextFont font;
enum iTextFont headingFont;
iBool monospaceGemini;
iBool monospaceGopher;
int lineWidth;
iBool bigFirstParagraph;
iBool forceLineWrap;
Expand Down
10 changes: 10 additions & 0 deletions src/ui/bindingswidget.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#include "command.h"
#include "util.h"
#include "app.h"
#if defined (iPlatformApple)
# include "macos.h"
#endif

iDeclareType(BindingItem)
typedef iListItemClass iBindingItemClass;
Expand Down Expand Up @@ -129,6 +132,13 @@ static void setActiveItem_BindingsWidget_(iBindingsWidget *d, size_t pos) {
item->isWaitingForEvent = iTrue;
invalidateItem_ListWidget(d->list, d->activePos);
}
#if defined (iPlatformApple)
/* Native menus must be disabled while grabbing keys so the shortcuts don't trigger. */
const iBool enableNativeMenus = (d->activePos == iInvalidPos);
enableMenu_MacOS("Edit", enableNativeMenus);
enableMenu_MacOS("View", enableNativeMenus);
enableMenu_MacOS("Identity", enableNativeMenus);
#endif
}

static iBool processEvent_BindingsWidget_(iBindingsWidget *d, const SDL_Event *ev) {
Expand Down
Loading

0 comments on commit 6e1e7d0

Please sign in to comment.