summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-16 11:08:01 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-16 11:08:01 +0300
commit05acbff09c6f74801997fcc3df507186d855232e (patch)
treeb1b87136d687655ba4fea06ccb967457d7778462
parent8fb0dc51a4b303f9c3a554cd8f72f7ae1a8da78b (diff)
macOS: Changing sidebar modes via touch bar
-rw-r--r--res/about/version.gmi2
-rw-r--r--src/macos.m26
2 files changed, 23 insertions, 5 deletions
diff --git a/res/about/version.gmi b/res/about/version.gmi
index 9eacc5d6..cfd32497 100644
--- a/res/about/version.gmi
+++ b/res/about/version.gmi
@@ -9,7 +9,7 @@
9## 0.2 9## 0.2
10* Fall back to software rendering automatically if accelerated graphics are not available. 10* Fall back to software rendering automatically if accelerated graphics are not available.
11* Added `--sw` option to force software rendering. 11* Added `--sw` option to force software rendering.
12* macOS: Touch bar buttons for Back, Forward, Find, New Tab. 12* macOS: Touch bar buttons for Back, Forward, Find, New Tab, and sidebar modes.
13 13
14## 0.1.1 14## 0.1.1
15* Fixed a potential crash at startup. 15* Fixed a potential crash at startup.
diff --git a/src/macos.m b/src/macos.m
index 6f833e12..b000fed9 100644
--- a/src/macos.m
+++ b/src/macos.m
@@ -28,10 +28,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
28 28
29#import <AppKit/AppKit.h> 29#import <AppKit/AppKit.h>
30 30
31static NSTouchBarItemIdentifier goBack_TouchId_ = @"fi.skyjake.Lagrange.back"; 31static NSTouchBarItemIdentifier goBack_TouchId_ = @"fi.skyjake.Lagrange.back";
32static NSTouchBarItemIdentifier goForward_TouchId_ = @"fi.skyjake.Lagrange.forward"; 32static NSTouchBarItemIdentifier goForward_TouchId_ = @"fi.skyjake.Lagrange.forward";
33static NSTouchBarItemIdentifier find_TouchId_ = @"fi.skyjake.Lagrange.find"; 33static NSTouchBarItemIdentifier find_TouchId_ = @"fi.skyjake.Lagrange.find";
34static NSTouchBarItemIdentifier newTab_TouchId_ = @"fi.skyjake.Lagrange.tabs.new"; 34static NSTouchBarItemIdentifier newTab_TouchId_ = @"fi.skyjake.Lagrange.tabs.new";
35static NSTouchBarItemIdentifier sidebarMode_TouchId_ = @"fi.skyjake.Lagrange.sidebar.mode";
35 36
36enum iTouchBarVariant { 37enum iTouchBarVariant {
37 default_TouchBarVariant, 38 default_TouchBarVariant,
@@ -205,6 +206,8 @@ static void appearanceChanged_MacOS_(NSString *name) {
205 NSTouchBarItemIdentifierFixedSpaceSmall, 206 NSTouchBarItemIdentifierFixedSpaceSmall,
206 find_TouchId_, 207 find_TouchId_,
207 NSTouchBarItemIdentifierFlexibleSpace, 208 NSTouchBarItemIdentifierFlexibleSpace,
209 sidebarMode_TouchId_,
210 NSTouchBarItemIdentifierFlexibleSpace,
208 newTab_TouchId_, 211 newTab_TouchId_,
209 NSTouchBarItemIdentifierOtherItemsProxy ]; 212 NSTouchBarItemIdentifierOtherItemsProxy ];
210 break; 213 break;
@@ -228,6 +231,11 @@ static void appearanceChanged_MacOS_(NSString *name) {
228 } 231 }
229} 232}
230 233
234- (void)sidebarModePressed:(id)sender {
235 NSSegmentedControl *seg = sender;
236 postCommandf_App("sidebar.mode arg:%d toggle:1", (int) [seg selectedSegment]);
237}
238
231- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar 239- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar
232 makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { 240 makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier {
233 iUnused(touchBar); 241 iUnused(touchBar);
@@ -249,6 +257,16 @@ static void appearanceChanged_MacOS_(NSString *name) {
249 widget:nil 257 widget:nil
250 command:@"focus.set id:find.input"]; 258 command:@"focus.set id:find.input"];
251 } 259 }
260 else if ([identifier isEqualToString:sidebarMode_TouchId_]) {
261 NSCustomTouchBarItem *item = [[NSCustomTouchBarItem alloc] initWithIdentifier:sidebarMode_TouchId_];
262 NSSegmentedControl *seg =
263 [NSSegmentedControl segmentedControlWithLabels:@[ @"Bookmarks", @"History", @"Identities", @"Outline"]
264 trackingMode:NSSegmentSwitchTrackingMomentary
265 target:[[NSApplication sharedApplication] delegate]
266 action:@selector(sidebarModePressed:)];
267 item.view = seg;
268 return item;
269 }
252 else if ([identifier isEqualToString:newTab_TouchId_]) { 270 else if ([identifier isEqualToString:newTab_TouchId_]) {
253 return [[CommandButton alloc] initWithIdentifier:identifier 271 return [[CommandButton alloc] initWithIdentifier:identifier
254 image:[NSImage imageNamed:NSImageNameTouchBarAddTemplate] 272 image:[NSImage imageNamed:NSImageNameTouchBarAddTemplate]