summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-01-26 07:34:39 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-01-26 07:34:39 +0200
commit85ccb7e82dc080e033d7aee621b53651aaa457e7 (patch)
tree65c05dedceb1de9ed95c52469ad2c643d63504a7 /src
parentc5668c7eb7004cb4edad0cb3a18422bf81a64c19 (diff)
parent37fefc85a9a23be7c3bc6dcddb8a30047459f534 (diff)
Merge branch 'pullrequests/Br0000k/dev' into dev
Diffstat (limited to 'src')
-rw-r--r--src/macos.m26
-rw-r--r--src/ui/documentwidget.c2
-rw-r--r--src/ui/inputwidget.c10
-rw-r--r--src/ui/keys.c3
-rw-r--r--src/ui/keys.h4
5 files changed, 38 insertions, 7 deletions
diff --git a/src/macos.m b/src/macos.m
index 4e214923..9d46d84b 100644
--- a/src/macos.m
+++ b/src/macos.m
@@ -241,10 +241,20 @@ static void appearanceChanged_MacOS_(NSString *name) {
241 241
242- (void)showPreferences { 242- (void)showPreferences {
243 postCommand_App("preferences"); 243 postCommand_App("preferences");
244 ignoreImmediateKeyDownEvents_();
245}
246
247static void ignoreImmediateKeyDownEvents_(void) {
248 /* SDL ignores menu key equivalents so the keydown events will be posted regardless.
249 However, we shouldn't double-activate menu items when a shortcut key is used in our
250 widgets. Quite a kludge: take advantage of Window's focus-acquisition threshold to
251 ignore the immediately following key down events. */
252 get_Window()->focusGainedAt = SDL_GetTicks();
244} 253}
245 254
246- (void)closeTab { 255- (void)closeTab {
247 postCommand_App("tabs.close"); 256 postCommand_App("tabs.close");
257 ignoreImmediateKeyDownEvents_();
248} 258}
249 259
250- (NSString *)commandForItem:(NSMenuItem *)menuItem { 260- (NSString *)commandForItem:(NSMenuItem *)menuItem {
@@ -255,11 +265,7 @@ static void appearanceChanged_MacOS_(NSString *name) {
255 NSString *command = [menuCommands objectForKey:[(NSMenuItem *)sender title]]; 265 NSString *command = [menuCommands objectForKey:[(NSMenuItem *)sender title]];
256 if (command) { 266 if (command) {
257 postCommand_App([command cStringUsingEncoding:NSUTF8StringEncoding]); 267 postCommand_App([command cStringUsingEncoding:NSUTF8StringEncoding]);
258 /* Shouldn't double-activate menu items in case the same key is used in our widgets. 268 ignoreImmediateKeyDownEvents_();
259 SDL ignores menu key equivalents so the keydown events will be posted regardless.
260 This is quite a kludge, but we can achieve this by taking advantage of Window's
261 focus-acquisition threshold for ignoring key events. */
262 get_Window()->focusGainedAt = SDL_GetTicks();
263 } 269 }
264} 270}
265 271
@@ -501,11 +507,17 @@ void handleCommand_MacOS(const char *cmd) {
501 NSApplication *app = [NSApplication sharedApplication]; 507 NSApplication *app = [NSApplication sharedApplication];
502 MyDelegate *myDel = (MyDelegate *) app.delegate; 508 MyDelegate *myDel = (MyDelegate *) app.delegate;
503 NSMenu *appMenu = [app mainMenu]; 509 NSMenu *appMenu = [app mainMenu];
510 int mainIndex = 0;
504 for (NSMenuItem *mainMenuItem in appMenu.itemArray) { 511 for (NSMenuItem *mainMenuItem in appMenu.itemArray) {
505 NSMenu *menu = mainMenuItem.submenu; 512 NSMenu *menu = mainMenuItem.submenu;
506 if (menu) { 513 if (menu) {
507 for (NSMenuItem *menuItem in menu.itemArray) { 514 int itemIndex = 0;
515 for (NSMenuItem *menuItem in menu.itemArray) {
508 NSString *command = [myDel commandForItem:menuItem]; 516 NSString *command = [myDel commandForItem:menuItem];
517 if (!command && mainIndex == 6 && itemIndex == 0) {
518 /* Window > Close */
519 command = @"tabs.close";
520 }
509 if (command) { 521 if (command) {
510 const iBinding *bind = findCommand_Keys( 522 const iBinding *bind = findCommand_Keys(
511 [command cStringUsingEncoding:NSUTF8StringEncoding]); 523 [command cStringUsingEncoding:NSUTF8StringEncoding]);
@@ -513,8 +525,10 @@ void handleCommand_MacOS(const char *cmd) {
513 setShortcut_NSMenuItem_(menuItem, bind->key, bind->mods); 525 setShortcut_NSMenuItem_(menuItem, bind->key, bind->mods);
514 } 526 }
515 } 527 }
528 itemIndex++;
516 } 529 }
517 } 530 }
531 mainIndex++;
518 } 532 }
519 } 533 }
520} 534}
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index c725a8f6..68f3c966 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -253,7 +253,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
253 resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag); 253 resizeToParentWidth_WidgetFlag | resizeToParentHeight_WidgetFlag);
254#if !defined (iPlatformApple) /* in system menu */ 254#if !defined (iPlatformApple) /* in system menu */
255 addAction_Widget(w, reload_KeyShortcut, "navigate.reload"); 255 addAction_Widget(w, reload_KeyShortcut, "navigate.reload");
256 addAction_Widget(w, SDLK_w, KMOD_PRIMARY, "tabs.close"); 256 addAction_Widget(w, closeTab_KeyShortcut, "tabs.close");
257 addAction_Widget(w, SDLK_d, KMOD_PRIMARY, "bookmark.add"); 257 addAction_Widget(w, SDLK_d, KMOD_PRIMARY, "bookmark.add");
258 addAction_Widget(w, subscribeToPage_KeyModifier, "feeds.subscribe"); 258 addAction_Widget(w, subscribeToPage_KeyModifier, "feeds.subscribe");
259#endif 259#endif
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index 6992bbec..62f0341e 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -224,6 +224,16 @@ static void updateBuffered_InputWidget_(iInputWidget *d) {
224} 224}
225 225
226void setText_InputWidget(iInputWidget *d, const iString *text) { 226void setText_InputWidget(iInputWidget *d, const iString *text) {
227 if (d->inFlags & isUrl_InputWidgetFlag) {
228 /* If user wants URLs encoded, also Punycode the domain. */
229 if (!prefs_App()->decodeUserVisibleURLs) {
230 iString *enc = collect_String(copy_String(text));
231 /* Prevent address bar spoofing (mentioned as IDN homograph attack in
232 https://github.com/skyjake/lagrange/issues/73) */
233 punyEncodeUrlHost_String(enc);
234 text = enc;
235 }
236 }
227 clearUndo_InputWidget_(d); 237 clearUndo_InputWidget_(d);
228 clear_Array(&d->text); 238 clear_Array(&d->text);
229 iConstForEach(String, i, text) { 239 iConstForEach(String, i, text) {
diff --git a/src/ui/keys.c b/src/ui/keys.c
index ec681b6f..656a52ac 100644
--- a/src/ui/keys.c
+++ b/src/ui/keys.c
@@ -80,9 +80,12 @@ static const struct { int id; iMenuItem bind; int flags; } defaultBindings_[] =
80 { 45, { "Open link in new tab via home row keys", 'f', KMOD_SHIFT, "document.linkkeys arg:1 newtab:1" }, 0 }, 80 { 45, { "Open link in new tab via home row keys", 'f', KMOD_SHIFT, "document.linkkeys arg:1 newtab:1" }, 0 },
81 { 46, { "Hover on link via home row keys", 'h', 0, "document.linkkeys arg:1 hover:1" }, 0 }, 81 { 46, { "Hover on link via home row keys", 'h', 0, "document.linkkeys arg:1 hover:1" }, 0 },
82 { 47, { "Next set of home row key links", '.', 0, "document.linkkeys more:1" }, 0 }, 82 { 47, { "Next set of home row key links", '.', 0, "document.linkkeys more:1" }, 0 },
83 { 50, { "Add bookmark", 'd', KMOD_PRIMARY, "bookmark.add" }, 0 },
83 { 70, { "Zoom in", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" }, 0 }, 84 { 70, { "Zoom in", SDLK_EQUALS, KMOD_PRIMARY, "zoom.delta arg:10" }, 0 },
84 { 71, { "Zoom out", SDLK_MINUS, KMOD_PRIMARY, "zoom.delta arg:-10" }, 0 }, 85 { 71, { "Zoom out", SDLK_MINUS, KMOD_PRIMARY, "zoom.delta arg:-10" }, 0 },
85 { 72, { "Reset zoom", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" }, 0 }, 86 { 72, { "Reset zoom", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" }, 0 },
87 { 76, { "New tab", newTab_KeyShortcut, "tabs.new" }, 0 },
88 { 77, { "Close tab", closeTab_KeyShortcut, "tabs.close" }, 0 },
86 { 80, { "Previous tab", prevTab_KeyShortcut, "tabs.prev" }, 0 }, 89 { 80, { "Previous tab", prevTab_KeyShortcut, "tabs.prev" }, 0 },
87 { 81, { "Next tab", nextTab_KeyShortcut, "tabs.next" }, 0 }, 90 { 81, { "Next tab", nextTab_KeyShortcut, "tabs.next" }, 0 },
88 { 100,{ "Toggle show URL on hover", '/', KMOD_PRIMARY, "prefs.hoverlink.toggle" }, 0 }, 91 { 100,{ "Toggle show URL on hover", '/', KMOD_PRIMARY, "prefs.hoverlink.toggle" }, 0 },
diff --git a/src/ui/keys.h b/src/ui/keys.h
index 8bcd4f53..f6f0b465 100644
--- a/src/ui/keys.h
+++ b/src/ui/keys.h
@@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28 28
29#if defined (iPlatformApple) 29#if defined (iPlatformApple)
30# define reload_KeyShortcut SDLK_r, KMOD_PRIMARY 30# define reload_KeyShortcut SDLK_r, KMOD_PRIMARY
31# define newTab_KeyShortcut SDLK_t, KMOD_PRIMARY
32# define closeTab_KeyShortcut SDLK_w, KMOD_PRIMARY
31# define prevTab_KeyShortcut SDLK_LEFTBRACKET, KMOD_SHIFT | KMOD_PRIMARY 33# define prevTab_KeyShortcut SDLK_LEFTBRACKET, KMOD_SHIFT | KMOD_PRIMARY
32# define nextTab_KeyShortcut SDLK_RIGHTBRACKET, KMOD_SHIFT | KMOD_PRIMARY 34# define nextTab_KeyShortcut SDLK_RIGHTBRACKET, KMOD_SHIFT | KMOD_PRIMARY
33# define navigateBack_KeyShortcut SDLK_LEFT, KMOD_PRIMARY 35# define navigateBack_KeyShortcut SDLK_LEFT, KMOD_PRIMARY
@@ -40,6 +42,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
40# define subscribeToPage_KeyModifier SDLK_d, KMOD_SHIFT | KMOD_PRIMARY 42# define subscribeToPage_KeyModifier SDLK_d, KMOD_SHIFT | KMOD_PRIMARY
41#else 43#else
42# define reload_KeyShortcut SDLK_r, KMOD_PRIMARY 44# define reload_KeyShortcut SDLK_r, KMOD_PRIMARY
45# define newTab_KeyShortcut SDLK_t, KMOD_PRIMARY
46# define closeTab_KeyShortcut SDLK_w, KMOD_PRIMARY
43# define prevTab_KeyShortcut SDLK_PAGEUP, KMOD_PRIMARY 47# define prevTab_KeyShortcut SDLK_PAGEUP, KMOD_PRIMARY
44# define nextTab_KeyShortcut SDLK_PAGEDOWN, KMOD_PRIMARY 48# define nextTab_KeyShortcut SDLK_PAGEDOWN, KMOD_PRIMARY
45# define navigateBack_KeyShortcut SDLK_LEFT, KMOD_ALT 49# define navigateBack_KeyShortcut SDLK_LEFT, KMOD_ALT