From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.devel Subject: NS port horizontal scroll-bars Date: Sun, 24 Apr 2016 17:01:23 +0100 Message-ID: <20160424160123.GA37657@breton.local> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="jRHKVT23PllUwdXP" X-Trace: ger.gmane.org 1461513710 20760 80.91.229.3 (24 Apr 2016 16:01:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 24 Apr 2016 16:01:50 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 24 18:01:50 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1auMTl-00051M-NA for ged-emacs-devel@m.gmane.org; Sun, 24 Apr 2016 18:01:49 +0200 Original-Received: from localhost ([::1]:55853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1auMTl-0007H7-5Q for ged-emacs-devel@m.gmane.org; Sun, 24 Apr 2016 12:01:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1auMTS-00079q-6N for emacs-devel@gnu.org; Sun, 24 Apr 2016 12:01:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1auMTQ-0000II-9p for emacs-devel@gnu.org; Sun, 24 Apr 2016 12:01:30 -0400 Original-Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:36099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1auMTP-0000IB-U9 for emacs-devel@gnu.org; Sun, 24 Apr 2016 12:01:28 -0400 Original-Received: by mail-wm0-x22f.google.com with SMTP id v188so71994071wme.1 for ; Sun, 24 Apr 2016 09:01:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=sender:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=rAyi7avhCwqgpKgQW/+Qaw0Q4Db+ZttRbuDBQEGZrkI=; b=W30w7sFqFoy4WY4rzsTuYS8+XRkAidJjoSvB/w4I5lqXC3CCsPvQsCisTN1aQSi13n f3OLEiypiC6Iots1Ro4qr7TmpC//e4P0vY6HCBF9qYIKPRCmy/Bx3pGdIny8vOcQloN5 2vnUfq6OXlWCjsE/KgaDarnccRMKNxl5eN61OCUir2WaW983VD2ktE+BTZs9OhmpdO+e //pjQV0n7pOp786My7r2XI15NO1EOYWCiW7bD71CdSkNe8OG/huGypunFmolKCJ1f9to Tw8NbCbdNNjBpRlEVgaBZ5p8AZTe5iFYfwxgbPrz/Ex+naFocWdHBCeTL8kWNk1MzKEL gSFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:subject:message-id :mime-version:content-disposition:user-agent; bh=rAyi7avhCwqgpKgQW/+Qaw0Q4Db+ZttRbuDBQEGZrkI=; b=H4h/tWwPal2Yg6HxFSZ8hlt92uc6V2ieESjVjGzjPQvDim7l0r0JbQgCV9rMfIzvj/ biGxIWYY547nTff0Kx6CEsTl/9N4yodAZwv9sqga3U/1EfkpZS/kfsV0KW931xxz7ogY enVaDAQGI7KzCqtsA1ESfOERAEeOvk4wLx5Nb3Ee2in31dN+ubGlQU345JKchEdKgKoo 1VkROMrIyHoenReOW+e643ic48QZFGVHrSmdX6uZPr9II9SlA2dWKn/RHM+2uZ3/9UT7 Em38I1R+9ccZwUI8gu/6n4rV/We+fIpU/mBA3VEyoMNgyO9d+3ARFK3koDMuZ+QRMhZT ihPQ== X-Gm-Message-State: AOPr4FW6PQsIaNNSr73fEuORaBaMsbd17zCVUBoeSQ8GnZ2VEpgp1dS154hAyrJenCLs0g== X-Received: by 10.28.171.8 with SMTP id u8mr7119480wme.97.1461513687015; Sun, 24 Apr 2016 09:01:27 -0700 (PDT) Original-Received: from breton.local (ip6-2001-08b0-03f8-8129-d503-4636-fb75-3da7.holly.idiocy.org. [2001:8b0:3f8:8129:d503:4636:fb75:3da7]) by smtp.gmail.com with ESMTPSA id kj9sm19163628wjb.14.2016.04.24.09.01.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Apr 2016 09:01:26 -0700 (PDT) Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22f X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:203261 Archived-At: --jRHKVT23PllUwdXP Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I've been trying to complete the horizontal scroll-bars implementation in the NS port and have run into a bit of a problem I can't work out. They display correctly, and when you click on them they, I think, send a correctly formatted emacs_event, but nothing happens. Vertical scroll-bars work as expected. Have I missed somewhere where I need to enable the horizontal scroll-bar events or something? Any pointers would be appreciated. I've attached a patch containing what I've done so far. -- Alan Third --jRHKVT23PllUwdXP Content-Type: text/plain; charset=us-ascii Content-Description: Horizontal scroll-bars patch Content-Disposition: attachment; filename="horiz-scrollers-argh.patch" diff --git a/lisp/scroll-bar.el b/lisp/scroll-bar.el index 5cfa2c4..01194f9 100644 --- a/lisp/scroll-bar.el +++ b/lisp/scroll-bar.el @@ -149,7 +149,8 @@ horizontal-scroll-bars-available-p (and (display-graphic-p) (boundp 'x-toolkit-scroll-bars) x-toolkit-scroll-bars - (not (eq (window-system) 'ns)))) + ;; (not (eq (window-system) 'ns)) + )) (define-minor-mode horizontal-scroll-bar-mode "Toggle horizontal scroll bars on all frames (Horizontal Scroll Bar mode). diff --git a/src/nsterm.h b/src/nsterm.h index 0aea9cc..93b19e4 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -72,7 +72,7 @@ typedef float EmacsCGFloat; Hint: keep the trailing whitespace -- the version control system will reject accidental commits. */ -/* #define NSTRACE_ENABLED 1 */ +#define NSTRACE_ENABLED 1 /* When non-zero, trace output is enabled for all parts, except those @@ -681,6 +681,8 @@ char const * nstrace_fullscreen_type_name (int); BOOL condemned; + BOOL horizontal; + /* optimize against excessive positioning calls generated by emacs */ int em_position; int em_portion; diff --git a/src/nsterm.m b/src/nsterm.m index 34c5395..91af34f 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -4442,11 +4442,11 @@ ns_set_horizontal_scroll_bar (struct window *window, NSTRACE ("ns_set_horizontal_scroll_bar"); /* Get dimensions. */ - window_box (window, ANY_AREA, 0, &window_x, &window_width, 0); + window_box (window, ANY_AREA, &window_x, 0, &window_width, 0); left = window_x; width = window_width; height = WINDOW_CONFIG_SCROLL_BAR_LINES (window) * FRAME_LINE_HEIGHT (f); - top = WINDOW_SCROLL_BAR_AREA_Y (window); + top = WINDOW_SCROLL_BAR_AREA_Y (window) - FRAME_LINE_HEIGHT (f); r = NSMakeRect (left, top, width, height); /* the parent view is flipped, so we need to flip y value */ @@ -4484,10 +4484,10 @@ ns_set_horizontal_scroll_bar (struct window *window, NSRect oldRect; bar = XNS_SCROLL_BAR (window->horizontal_scroll_bar); oldRect = [bar frame]; - r.size.width = oldRect.size.width; + r.size.height = oldRect.size.height; if (FRAME_LIVE_P (f) && !NSEqualRects (oldRect, r)) { - if (oldRect.origin.x != r.origin.x) + if (oldRect.origin.y != r.origin.y) ns_clear_frame_area (f, left, top, width, height); [bar setFrame: r]; update_p = YES; @@ -8110,12 +8110,21 @@ not_in_argv (NSString *arg) return r; } - - initFrame: (NSRect )r window: (Lisp_Object)nwin { NSTRACE ("[EmacsScroller initFrame: window:]"); - r.size.width = [EmacsScroller scrollerWidth]; + if (r.size.width > r.size.height) + { + horizontal = YES; + r.size.height = [EmacsScroller scrollerWidth]; + } + else + { + horizontal = NO; + r.size.width = [EmacsScroller scrollerWidth]; + } + [super initWithFrame: r/*NSMakeRect (0, 0, 0, 0)*/]; [self setContinuous: YES]; [self setEnabled: YES]; @@ -8131,7 +8140,10 @@ not_in_argv (NSString *arg) window = XWINDOW (nwin); condemned = NO; - pixel_height = NSHeight (r); + if (horizontal) + pixel_height = NSWidth (r); + else + pixel_height = NSHeight (r); if (pixel_height == 0) pixel_height = 1; min_portion = 20 / pixel_height; @@ -8162,7 +8174,10 @@ not_in_argv (NSString *arg) NSTRACE ("[EmacsScroller setFrame:]"); /* block_input (); */ - pixel_height = NSHeight (newRect); + if (newRect.size.width > newRect.size.height) + pixel_height = NSWidth (newRect); + else + pixel_height = NSHeight (newRect); if (pixel_height == 0) pixel_height = 1; min_portion = 20 / pixel_height; [super setFrame: newRect]; @@ -8174,7 +8189,12 @@ not_in_argv (NSString *arg) { NSTRACE ("[EmacsScroller dealloc]"); if (window) - wset_vertical_scroll_bar (window, Qnil); + { + if (horizontal) + wset_horizontal_scroll_bar (window, Qnil); + else + wset_vertical_scroll_bar (window, Qnil); + } window = 0; [super dealloc]; } @@ -8289,10 +8309,15 @@ not_in_argv (NSString *arg) XSETWINDOW (win, window); emacs_event->frame_or_window = win; emacs_event->timestamp = EV_TIMESTAMP (e); - emacs_event->kind = SCROLL_BAR_CLICK_EVENT; - emacs_event->arg = Qnil; - XSETINT (emacs_event->x, loc * pixel_height); + if (horizontal) + emacs_event->kind = HORIZONTAL_SCROLL_BAR_CLICK_EVENT; + else + emacs_event->kind = SCROLL_BAR_CLICK_EVENT; + XSETINT (emacs_event->x, loc); XSETINT (emacs_event->y, pixel_height-20); + emacs_event->arg = Qnil; + + printf("x: %d, y: %d\n", emacs_event->x, emacs_event->y); if (q_event_ptr) { @@ -8355,13 +8380,13 @@ not_in_argv (NSString *arg) switch (part) { case NSScrollerDecrementPage: - last_hit_part = scroll_bar_above_handle; inc = -1.0; break; + last_hit_part = scroll_bar_above_handle; break; case NSScrollerIncrementPage: - last_hit_part = scroll_bar_below_handle; inc = 1.0; break; + last_hit_part = scroll_bar_below_handle; break; case NSScrollerDecrementLine: - last_hit_part = scroll_bar_up_arrow; inc = -0.1; break; + last_hit_part = scroll_bar_up_arrow; break; case NSScrollerIncrementLine: - last_hit_part = scroll_bar_down_arrow; inc = 0.1; break; + last_hit_part = scroll_bar_down_arrow; break; case NSScrollerKnob: last_hit_part = scroll_bar_handle; break; case NSScrollerKnobSlot: /* GNUstep-only */ @@ -8372,36 +8397,34 @@ not_in_argv (NSString *arg) return; } - if (inc != 0.0) - { - pos = 0; /* ignored */ - - /* set a timer to repeat, as we can't let superclass do this modally */ - scroll_repeat_entry - = [[NSTimer scheduledTimerWithTimeInterval: SCROLL_BAR_FIRST_DELAY - target: self - selector: @selector (repeatScroll:) - userInfo: 0 - repeats: YES] - retain]; - } - else + if (part == NSScrollerKnob || part == NSScrollerKnobSlot) { /* handle, or on GNUstep possibly slot */ NSEvent *fake_event; - + int length; + /* compute float loc in slot and mouse offset on knob */ sr = [self convertRect: [self rectForPart: NSScrollerKnobSlot] toView: nil]; - loc = NSHeight (sr) - ([e locationInWindow].y - NSMinY (sr)); + if (horizontal) + { + length = NSWidth (sr); + loc = ([e locationInWindow].x - NSMinX (sr)); + } + else + { + length = NSHeight (sr); + loc = length - ([e locationInWindow].y - NSMinY (sr)); + } + if (loc <= 0.0) { loc = 0.0; edge = -1; } - else if (loc >= NSHeight (sr)) + else if (loc >= length) { - loc = NSHeight (sr); + loc = length; edge = 1; } @@ -8411,17 +8434,16 @@ not_in_argv (NSString *arg) { kr = [self convertRect: [self rectForPart: NSScrollerKnob] toView: nil]; - kloc = NSHeight (kr) - ([e locationInWindow].y - NSMinY (kr)); + if (horizontal) + kloc = ([e locationInWindow].x - NSMinX (kr)); + else + kloc = NSHeight (kr) - ([e locationInWindow].y - NSMinY (kr)); } last_mouse_offset = kloc; - /* if knob, tell emacs a location offset by knob pos - (to indicate top of handle) */ - if (part == NSScrollerKnob) - pos = (loc - last_mouse_offset) / NSHeight (sr); - else - /* else this is a slot click on GNUstep: go straight there */ - pos = loc / NSHeight (sr); + if (part != NSScrollerKnob) + /* this is a slot click on GNUstep: go straight there */ + pos = loc / length; /* send a fake mouse-up to super to preempt modal -trackKnob: mode */ fake_event = [NSEvent mouseEventWithType: NSLeftMouseUp @@ -8435,6 +8457,19 @@ not_in_argv (NSString *arg) pressure: [e pressure]]; [super mouseUp: fake_event]; } + else + { + pos = 0; /* ignored */ + + /* set a timer to repeat, as we can't let superclass do this modally */ + scroll_repeat_entry + = [[NSTimer scheduledTimerWithTimeInterval: SCROLL_BAR_FIRST_DELAY + target: self + selector: @selector (repeatScroll:) + userInfo: 0 + repeats: YES] + retain]; + } if (part != NSScrollerKnob) [self sendScrollEventAtLoc: pos fromEvent: e]; @@ -8446,23 +8481,34 @@ not_in_argv (NSString *arg) { NSRect sr; double loc, pos; - + int length; + NSTRACE ("[EmacsScroller mouseDragged:]"); sr = [self convertRect: [self rectForPart: NSScrollerKnobSlot] toView: nil]; - loc = NSHeight (sr) - ([e locationInWindow].y - NSMinY (sr)); + + if (horizontal) + { + length = NSWidth (sr); + loc = ([e locationInWindow].x - NSMinX (sr)); + } + else + { + length = NSHeight (sr); + loc = length - ([e locationInWindow].y - NSMinY (sr)); + } if (loc <= 0.0) { loc = 0.0; } - else if (loc >= NSHeight (sr) + last_mouse_offset) + else if (loc >= length + last_mouse_offset) { - loc = NSHeight (sr) + last_mouse_offset; + loc = length + last_mouse_offset; } - pos = (loc - last_mouse_offset) / NSHeight (sr); + pos = (loc - last_mouse_offset); [self sendScrollEventAtLoc: pos fromEvent: e]; } diff --git a/src/window.h b/src/window.h index 0cfff88..a1c4aaa 100644 --- a/src/window.h +++ b/src/window.h @@ -786,7 +786,7 @@ wset_next_buffers (struct window *w, Lisp_Object val) || WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (W)) #if (defined (HAVE_WINDOW_SYSTEM) \ - && ((defined (USE_TOOLKIT_SCROLL_BARS) && !defined (HAVE_NS)) \ + && ((defined (USE_TOOLKIT_SCROLL_BARS)) \ || defined (HAVE_NTGUI))) # define USE_HORIZONTAL_SCROLL_BARS true #else --jRHKVT23PllUwdXP--