shithub: drawterm

Download patch

ref: 229d7bb35315ade6f25d96071adfd6933a50015d
parent: f11139d4c918802a87730bc14d094670ee4ce572
author: Romano <me+git@fallglow.com>
date: Mon Aug 12 19:44:17 EDT 2024

osx-cocoa: make riow more operational

* map command key to mod4 so riow can be used
* update submenu shortcuts to not overlap with riow f and h hotkeys
* when cmd-q is pressed, show confirmation modal

--- a/gui-cocoa/screen.m
+++ b/gui-cocoa/screen.m
@@ -310,13 +310,29 @@
 	cpubody();
 }
 
+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
+{
+	if([sender mainWindow] == nil)
+		return NSTerminateNow;
+
+	NSAlert *alert = [[NSAlert alloc] init];
+	[alert setMessageText:@"Really quit drawterm?"];
+	[alert addButtonWithTitle:@"Yes"];
+	[alert addButtonWithTitle:@"Cancel"];
+	[alert setAlertStyle:NSAlertStyleCritical];
+	int choice = [alert runModal];
+	if(choice == NSAlertFirstButtonReturn)
+		return NSTerminateNow;
+	return NSTerminateCancel;
+}
+
 - (void) applicationDidFinishLaunching:(NSNotification *)aNotification
 {
 	LOG(@"BEGIN");
 
 	NSMenu *sm = [NSMenu new];
-	[sm addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
-	[sm addItemWithTitle:@"Hide" action:@selector(hide:) keyEquivalent:@"h"];
+	[sm addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"F"];
+	[sm addItemWithTitle:@"Hide" action:@selector(hide:) keyEquivalent:@"H"];
 	[sm addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
 	NSMenu *m = [NSMenu new];
 	[m addItemWithTitle:@"DEVDRAW" action:NULL keyEquivalent:@""];
@@ -549,11 +565,13 @@
 		}else
 			kbdkey(Kalt, 1);
 	}
-	if((x & NSEventModifierFlagCommand) != 0)
+	if((x & NSEventModifierFlagCommand) != 0){
 		if(u){
 			u |= 4;
 			[self sendmouse:u];
-		}
+		}else
+			kbdkey(Kmod4, 1);
+	}
 	if((x & ~_mods & NSEventModifierFlagCapsLock) != 0)
 		kbdkey(Kcaps, 1);
 	if((~x & _mods & NSEventModifierFlagShift) != 0)
@@ -568,6 +586,8 @@
 			_breakcompose = NO;
 		}
 	}
+	if((~x & NSEventModifierFlagCommand) != 0)
+		kbdkey(Kmod4, 0);
 	if((~x & _mods & NSEventModifierFlagCapsLock) != 0)
 		kbdkey(Kcaps, 0);
 	_mods = x;
@@ -585,6 +605,10 @@
 	if((_mods & NSEventModifierFlagOption) != 0){
 		kbdkey(Kalt, 0);
 		_mods ^= NSEventModifierFlagOption;
+	}
+	if((_mods & NSEventModifierFlagCommand) != 0){
+		kbdkey(Kmod4, 0);
+		_mods ^= NSEventModifierFlagCommand;
 	}
 }