diff options
| author | Po Lu | 2022-05-23 11:13:45 +0800 |
|---|---|---|
| committer | Po Lu | 2022-05-23 11:13:45 +0800 |
| commit | 5346b67fc27f50abeec3c4f72252a8d9a36f2e6b (patch) | |
| tree | 3d0d97bf14696172990508e3329461ba1df58245 /src | |
| parent | 20662ecd214fbe2a9f200085b9194a6f7677d447 (diff) | |
| download | emacs-5346b67fc27f50abeec3c4f72252a8d9a36f2e6b.tar.gz emacs-5346b67fc27f50abeec3c4f72252a8d9a36f2e6b.zip | |
Implement monitor change functions on GNUstep
* src/nsfns.m (Fns_display_monitor_attributes_list): Fix coding
style.
* src/nsterm.m (nstrace_leave, nstrace_restore_global_trace_state)
(nstrace_fullscreen_type_name): Fix coding style.
(ns_displays_reconfigured, ns_term_init): Make a record of the
previous display attributes list and avoid storing duplicate
events.
([EmacsApp init]): Listen for
NSApplicationDidChangeScreenParametersNotification.
([EmacsApp updateMonitors:]): New method.
(syms_of_nsterm): New staticpro.
Diffstat (limited to 'src')
| -rw-r--r-- | src/nsfns.m | 19 | ||||
| -rw-r--r-- | src/nsterm.m | 104 |
2 files changed, 95 insertions, 28 deletions
diff --git a/src/nsfns.m b/src/nsfns.m index 818ba6f40f1..20c36209eb5 100644 --- a/src/nsfns.m +++ b/src/nsfns.m | |||
| @@ -2769,7 +2769,8 @@ Internal use only, use `display-monitor-attributes-list' instead. */) | |||
| 2769 | } | 2769 | } |
| 2770 | else | 2770 | else |
| 2771 | { | 2771 | { |
| 2772 | // Flip y coordinate as NS has y starting from the bottom. | 2772 | /* Flip y coordinate as NS screen coordinates originate from |
| 2773 | the bottom. */ | ||
| 2773 | y = (short) (primary_display_height - fr.size.height - fr.origin.y); | 2774 | y = (short) (primary_display_height - fr.size.height - fr.origin.y); |
| 2774 | vy = (short) (primary_display_height - | 2775 | vy = (short) (primary_display_height - |
| 2775 | vfr.size.height - vfr.origin.y); | 2776 | vfr.size.height - vfr.origin.y); |
| @@ -2781,11 +2782,12 @@ Internal use only, use `display-monitor-attributes-list' instead. */) | |||
| 2781 | m->geom.height = (unsigned short) fr.size.height; | 2782 | m->geom.height = (unsigned short) fr.size.height; |
| 2782 | 2783 | ||
| 2783 | m->work.x = (short) vfr.origin.x; | 2784 | m->work.x = (short) vfr.origin.x; |
| 2784 | // y is flipped on NS, so vy - y are pixels missing at the bottom, | 2785 | /* y is flipped on NS, so vy - y are pixels missing at the |
| 2785 | // and fr.size.height - vfr.size.height are pixels missing in total. | 2786 | bottom, and fr.size.height - vfr.size.height are pixels |
| 2786 | // Pixels missing at top are | 2787 | missing in total. |
| 2787 | // fr.size.height - vfr.size.height - vy + y. | 2788 | |
| 2788 | // work.y is then pixels missing at top + y. | 2789 | Pixels missing at top are fr.size.height - vfr.size.height - |
| 2790 | vy + y. work.y is then pixels missing at top + y. */ | ||
| 2789 | m->work.y = (short) (fr.size.height - vfr.size.height) - vy + y + y; | 2791 | m->work.y = (short) (fr.size.height - vfr.size.height) - vy + y + y; |
| 2790 | m->work.width = (unsigned short) vfr.size.width; | 2792 | m->work.width = (unsigned short) vfr.size.width; |
| 2791 | m->work.height = (unsigned short) vfr.size.height; | 2793 | m->work.height = (unsigned short) vfr.size.height; |
| @@ -2800,13 +2802,14 @@ Internal use only, use `display-monitor-attributes-list' instead. */) | |||
| 2800 | } | 2802 | } |
| 2801 | 2803 | ||
| 2802 | #else | 2804 | #else |
| 2803 | // Assume 92 dpi as x-display-mm-height/x-display-mm-width does. | 2805 | /* Assume 92 dpi as x-display-mm-height and x-display-mm-width |
| 2806 | do. */ | ||
| 2804 | m->mm_width = (int) (25.4 * fr.size.width / 92.0); | 2807 | m->mm_width = (int) (25.4 * fr.size.width / 92.0); |
| 2805 | m->mm_height = (int) (25.4 * fr.size.height / 92.0); | 2808 | m->mm_height = (int) (25.4 * fr.size.height / 92.0); |
| 2806 | #endif | 2809 | #endif |
| 2807 | } | 2810 | } |
| 2808 | 2811 | ||
| 2809 | // Primary monitor is always first for NS. | 2812 | /* Primary monitor is always ordered first for NS. */ |
| 2810 | attributes_list = ns_make_monitor_attribute_list (monitors, n_monitors, | 2813 | attributes_list = ns_make_monitor_attribute_list (monitors, n_monitors, |
| 2811 | 0, "NS"); | 2814 | 0, "NS"); |
| 2812 | 2815 | ||
diff --git a/src/nsterm.m b/src/nsterm.m index 67b02c7a54a..d7e62a70c49 100644 --- a/src/nsterm.m +++ b/src/nsterm.m | |||
| @@ -79,6 +79,9 @@ static EmacsMenu *dockMenu; | |||
| 79 | static EmacsMenu *mainMenu; | 79 | static EmacsMenu *mainMenu; |
| 80 | #endif | 80 | #endif |
| 81 | 81 | ||
| 82 | /* The last known monitor attributes list. */ | ||
| 83 | static Lisp_Object last_known_monitors; | ||
| 84 | |||
| 82 | /* ========================================================================== | 85 | /* ========================================================================== |
| 83 | 86 | ||
| 84 | NSTRACE, Trace support. | 87 | NSTRACE, Trace support. |
| @@ -89,8 +92,8 @@ static EmacsMenu *mainMenu; | |||
| 89 | 92 | ||
| 90 | /* The following use "volatile" since they can be accessed from | 93 | /* The following use "volatile" since they can be accessed from |
| 91 | parallel threads. */ | 94 | parallel threads. */ |
| 92 | volatile int nstrace_num = 0; | 95 | volatile int nstrace_num; |
| 93 | volatile int nstrace_depth = 0; | 96 | volatile int nstrace_depth; |
| 94 | 97 | ||
| 95 | /* When 0, no trace is emitted. This is used by NSTRACE_WHEN and | 98 | /* When 0, no trace is emitted. This is used by NSTRACE_WHEN and |
| 96 | NSTRACE_UNLESS to silence functions called. | 99 | NSTRACE_UNLESS to silence functions called. |
| @@ -101,33 +104,41 @@ volatile int nstrace_depth = 0; | |||
| 101 | volatile int nstrace_enabled_global = 1; | 104 | volatile int nstrace_enabled_global = 1; |
| 102 | 105 | ||
| 103 | /* Called when nstrace_enabled goes out of scope. */ | 106 | /* Called when nstrace_enabled goes out of scope. */ |
| 104 | void nstrace_leave(int * pointer_to_nstrace_enabled) | 107 | void |
| 108 | nstrace_leave (int *pointer_to_nstrace_enabled) | ||
| 105 | { | 109 | { |
| 106 | if (*pointer_to_nstrace_enabled) | 110 | if (*pointer_to_nstrace_enabled) |
| 107 | { | 111 | --nstrace_depth; |
| 108 | --nstrace_depth; | ||
| 109 | } | ||
| 110 | } | 112 | } |
| 111 | 113 | ||
| 112 | 114 | ||
| 113 | /* Called when nstrace_saved_enabled_global goes out of scope. */ | 115 | /* Called when nstrace_saved_enabled_global goes out of scope. */ |
| 114 | void nstrace_restore_global_trace_state(int * pointer_to_saved_enabled_global) | 116 | void |
| 117 | nstrace_restore_global_trace_state (int *pointer_to_saved_enabled_global) | ||
| 115 | { | 118 | { |
| 116 | nstrace_enabled_global = *pointer_to_saved_enabled_global; | 119 | nstrace_enabled_global = *pointer_to_saved_enabled_global; |
| 117 | } | 120 | } |
| 118 | 121 | ||
| 119 | 122 | ||
| 120 | char const * nstrace_fullscreen_type_name (int fs_type) | 123 | const char * |
| 124 | nstrace_fullscreen_type_name (int fs_type) | ||
| 121 | { | 125 | { |
| 122 | switch (fs_type) | 126 | switch (fs_type) |
| 123 | { | 127 | { |
| 124 | case -1: return "-1"; | 128 | case -1: |
| 125 | case FULLSCREEN_NONE: return "FULLSCREEN_NONE"; | 129 | return "-1"; |
| 126 | case FULLSCREEN_WIDTH: return "FULLSCREEN_WIDTH"; | 130 | case FULLSCREEN_NONE: |
| 127 | case FULLSCREEN_HEIGHT: return "FULLSCREEN_HEIGHT"; | 131 | return "FULLSCREEN_NONE"; |
| 128 | case FULLSCREEN_BOTH: return "FULLSCREEN_BOTH"; | 132 | case FULLSCREEN_WIDTH: |
| 129 | case FULLSCREEN_MAXIMIZED: return "FULLSCREEN_MAXIMIZED"; | 133 | return "FULLSCREEN_WIDTH"; |
| 130 | default: return "FULLSCREEN_?????"; | 134 | case FULLSCREEN_HEIGHT: |
| 135 | return "FULLSCREEN_HEIGHT"; | ||
| 136 | case FULLSCREEN_BOTH: | ||
| 137 | return "FULLSCREEN_BOTH"; | ||
| 138 | case FULLSCREEN_MAXIMIZED: | ||
| 139 | return "FULLSCREEN_MAXIMIZED"; | ||
| 140 | default: | ||
| 141 | return "FULLSCREEN_?????"; | ||
| 131 | } | 142 | } |
| 132 | } | 143 | } |
| 133 | #endif | 144 | #endif |
| @@ -5221,9 +5232,17 @@ ns_displays_reconfigured (CGDirectDisplayID display, | |||
| 5221 | { | 5232 | { |
| 5222 | struct input_event ie; | 5233 | struct input_event ie; |
| 5223 | union buffered_input_event *ev; | 5234 | union buffered_input_event *ev; |
| 5235 | Lisp_Object new_monitors; | ||
| 5224 | 5236 | ||
| 5225 | EVENT_INIT (ie); | 5237 | EVENT_INIT (ie); |
| 5226 | 5238 | ||
| 5239 | new_monitors = Fns_display_monitor_attributes_list (Qnil); | ||
| 5240 | |||
| 5241 | if (!NILP (Fequal (new_monitors, last_known_monitors))) | ||
| 5242 | return; | ||
| 5243 | |||
| 5244 | last_known_monitors = new_monitors; | ||
| 5245 | |||
| 5227 | ev = (kbd_store_ptr == kbd_buffer | 5246 | ev = (kbd_store_ptr == kbd_buffer |
| 5228 | ? kbd_buffer + KBD_BUFFER_SIZE - 1 | 5247 | ? kbd_buffer + KBD_BUFFER_SIZE - 1 |
| 5229 | : kbd_store_ptr - 1); | 5248 | : kbd_store_ptr - 1); |
| @@ -5601,6 +5620,7 @@ ns_term_init (Lisp_Object display_name) | |||
| 5601 | CGDisplayRegisterReconfigurationCallback (ns_displays_reconfigured, | 5620 | CGDisplayRegisterReconfigurationCallback (ns_displays_reconfigured, |
| 5602 | NULL); | 5621 | NULL); |
| 5603 | #endif | 5622 | #endif |
| 5623 | last_known_monitors = Fns_display_monitor_attributes_list (Qnil); | ||
| 5604 | 5624 | ||
| 5605 | NSTRACE_MSG ("ns_term_init done"); | 5625 | NSTRACE_MSG ("ns_term_init done"); |
| 5606 | 5626 | ||
| @@ -5642,6 +5662,10 @@ ns_term_shutdown (int sig) | |||
| 5642 | 5662 | ||
| 5643 | - (id)init | 5663 | - (id)init |
| 5644 | { | 5664 | { |
| 5665 | #ifdef NS_IMPL_GNUSTEP | ||
| 5666 | NSNotificationCenter *notification_center; | ||
| 5667 | #endif | ||
| 5668 | |||
| 5645 | NSTRACE ("[EmacsApp init]"); | 5669 | NSTRACE ("[EmacsApp init]"); |
| 5646 | 5670 | ||
| 5647 | if ((self = [super init])) | 5671 | if ((self = [super init])) |
| @@ -5654,6 +5678,14 @@ ns_term_shutdown (int sig) | |||
| 5654 | #endif | 5678 | #endif |
| 5655 | } | 5679 | } |
| 5656 | 5680 | ||
| 5681 | #ifdef NS_IMPL_GNUSTEP | ||
| 5682 | notification_center = [NSNotificationCenter defaultCenter]; | ||
| 5683 | [notification_center addObserver: self | ||
| 5684 | selector: @selector(updateMonitors:) | ||
| 5685 | name: NSApplicationDidChangeScreenParametersNotification | ||
| 5686 | object: nil]; | ||
| 5687 | #endif | ||
| 5688 | |||
| 5657 | return self; | 5689 | return self; |
| 5658 | } | 5690 | } |
| 5659 | 5691 | ||
| @@ -5666,11 +5698,11 @@ ns_term_shutdown (int sig) | |||
| 5666 | #define NSAppKitVersionNumber10_9 1265 | 5698 | #define NSAppKitVersionNumber10_9 1265 |
| 5667 | #endif | 5699 | #endif |
| 5668 | 5700 | ||
| 5669 | if ((int)NSAppKitVersionNumber != NSAppKitVersionNumber10_9) | 5701 | if ((int) NSAppKitVersionNumber != NSAppKitVersionNumber10_9) |
| 5670 | { | 5702 | { |
| 5671 | [super run]; | 5703 | [super run]; |
| 5672 | return; | 5704 | return; |
| 5673 | } | 5705 | } |
| 5674 | 5706 | ||
| 5675 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | 5707 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
| 5676 | 5708 | ||
| @@ -5854,6 +5886,36 @@ ns_term_shutdown (int sig) | |||
| 5854 | return YES; | 5886 | return YES; |
| 5855 | } | 5887 | } |
| 5856 | 5888 | ||
| 5889 | #ifdef NS_IMPL_GNUSTEP | ||
| 5890 | - (void) updateMonitors: (NSNotification *) notification | ||
| 5891 | { | ||
| 5892 | struct input_event ie; | ||
| 5893 | union buffered_input_event *ev; | ||
| 5894 | Lisp_Object new_monitors; | ||
| 5895 | |||
| 5896 | EVENT_INIT (ie); | ||
| 5897 | |||
| 5898 | new_monitors = Fns_display_monitor_attributes_list (Qnil); | ||
| 5899 | |||
| 5900 | if (!NILP (Fequal (new_monitors, last_known_monitors))) | ||
| 5901 | return; | ||
| 5902 | |||
| 5903 | last_known_monitors = new_monitors; | ||
| 5904 | |||
| 5905 | ev = (kbd_store_ptr == kbd_buffer | ||
| 5906 | ? kbd_buffer + KBD_BUFFER_SIZE - 1 | ||
| 5907 | : kbd_store_ptr - 1); | ||
| 5908 | |||
| 5909 | if (kbd_store_ptr != kbd_fetch_ptr | ||
| 5910 | && ev->ie.kind == MONITORS_CHANGED_EVENT) | ||
| 5911 | return; | ||
| 5912 | |||
| 5913 | ie.kind = MONITORS_CHANGED_EVENT; | ||
| 5914 | XSETTERMINAL (ie.arg, x_display_list->terminal); | ||
| 5915 | |||
| 5916 | kbd_buffer_store_event (&ie); | ||
| 5917 | } | ||
| 5918 | #endif | ||
| 5857 | 5919 | ||
| 5858 | /* ************************************************************************** | 5920 | /* ************************************************************************** |
| 5859 | 5921 | ||
| @@ -10575,4 +10637,6 @@ This variable is ignored on macOS < 10.7 and GNUstep. Default is t. */); | |||
| 10575 | syms_of_nsfont (); | 10637 | syms_of_nsfont (); |
| 10576 | #endif | 10638 | #endif |
| 10577 | 10639 | ||
| 10640 | last_known_monitors = Qnil; | ||
| 10641 | staticpro (&last_known_monitors); | ||
| 10578 | } | 10642 | } |