From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: YAMAMOTO Mitsuharu Newsgroups: gmane.emacs.devel Subject: Re: x-display-pixel-width/height inconsistency Date: Fri, 22 Mar 2013 08:29:55 +0900 Organization: Faculty of Science, Chiba University Message-ID: References: <514A5DE1.10009@gmx.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1363908616 23278 80.91.229.3 (21 Mar 2013 23:30:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Mar 2013 23:30:16 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Mar 22 00:30:42 2013 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 1UIowT-0000tD-6b for ged-emacs-devel@m.gmane.org; Fri, 22 Mar 2013 00:30:41 +0100 Original-Received: from localhost ([::1]:45520 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIow5-0003S9-QO for ged-emacs-devel@m.gmane.org; Thu, 21 Mar 2013 19:30:17 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:50540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIovw-0003Qx-Vv for emacs-devel@gnu.org; Thu, 21 Mar 2013 19:30:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIovq-00030G-Dx for emacs-devel@gnu.org; Thu, 21 Mar 2013 19:30:08 -0400 Original-Received: from mathmail.math.s.chiba-u.ac.jp ([133.82.132.2]:51614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIovp-0002ph-GN for emacs-devel@gnu.org; Thu, 21 Mar 2013 19:30:02 -0400 Original-Received: from church.math.s.chiba-u.ac.jp (church [133.82.132.36]) by mathmail.math.s.chiba-u.ac.jp (Postfix) with ESMTP id DC326C0561 for ; Fri, 22 Mar 2013 08:29:55 +0900 (JST) In-Reply-To: User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (=?ISO-8859-4?Q?Shij=F2?=) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 133.82.132.2 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:158040 Archived-At: >>>>> On Thu, 21 Mar 2013 10:44:29 +0900, YAMAMOTO Mitsuharu said: >> Then use >> w = GetSystemMetrics(SM_CXVIRTUALSCREEN); >> h = GetSystemMetrics(SM_CYVIRTUALSCREEN); > Thanks. I tried making a patch using them. Do you happen to know an > appropriate way to exclude Windows 95 and NT 4 where > SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN are not available? Patch updated. I used the condition (w32_major_version == 4 && w32_minor_version == 0) to distinguish Windows 95 and NT 4 from the other versions. Also, changes for the NS port are included. I'll install it in a few days if no problems found. YAMAMOTO Mitsuharu mituharu@math.s.chiba-u.ac.jp === modified file 'src/nsfns.m' *** src/nsfns.m 2013-03-20 09:56:19 +0000 --- src/nsfns.m 2013-03-21 23:16:54 +0000 *************** *** 144,187 **** } ! /* Let the user specify an Nextstep display with a frame. ! nil stands for the selected frame--or, if that is not an Nextstep frame, the first Nextstep display on the list. */ static struct ns_display_info * ! check_ns_display_info (Lisp_Object frame) { ! if (NILP (frame)) { ! struct frame *f = SELECTED_FRAME (); ! if (FRAME_NS_P (f) && FRAME_LIVE_P (f) ) ! return FRAME_NS_DISPLAY_INFO (f); else if (x_display_list != 0) ! return x_display_list; else error ("Nextstep windows are not in use or not initialized"); } ! else if (INTEGERP (frame)) { ! struct terminal *t = get_terminal (frame, 1); if (t->type != output_ns) ! error ("Terminal %"pI"d is not a Nextstep display", XINT (frame)); ! return t->display_info.ns; } ! else if (STRINGP (frame)) ! return ns_display_info_for_name (frame); else { ! FRAME_PTR f; ! ! CHECK_LIVE_FRAME (frame); ! f = XFRAME (frame); ! if (! FRAME_NS_P (f)) ! error ("non-Nextstep frame used"); ! return FRAME_NS_DISPLAY_INFO (f); } ! return NULL; /* shut compiler up */ } --- 144,188 ---- } ! /* Let the user specify a Nextstep display with a Lisp object. ! OBJECT may be nil, a frame or a terminal object. ! nil stands for the selected frame--or, if that is not a Nextstep frame, the first Nextstep display on the list. */ + static struct ns_display_info * ! check_ns_display_info (Lisp_Object object) { ! struct ns_display_info *dpyinfo = NULL; ! ! if (NILP (object)) { ! struct frame *sf = XFRAME (selected_frame); ! ! if (FRAME_NS_P (sf) && FRAME_LIVE_P (sf)) ! dpyinfo = FRAME_NS_DISPLAY_INFO (sf); else if (x_display_list != 0) ! dpyinfo = x_display_list; else error ("Nextstep windows are not in use or not initialized"); } ! else if (TERMINALP (object)) { ! struct terminal *t = get_terminal (object, 1); if (t->type != output_ns) ! error ("Terminal %"pI"d is not a Nextstep display", XINT (object)); ! dpyinfo = t->display_info.ns; } ! else if (STRINGP (object)) ! dpyinfo = ns_display_info_for_name (object); else { ! FRAME_PTR f = check_ns_frame (object); ! dpyinfo = FRAME_NS_DISPLAY_INFO (f); } ! ! return dpyinfo; } *************** *** 1699,1727 **** } ! DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, ! 0, 1, 0, ! doc: /* Return the height of Nextstep display server DISPLAY, in millimeters. ! DISPLAY should be a frame, the display name as a string, or a terminal ID. ! If omitted or nil, the selected frame's display is used. */) ! (Lisp_Object display) { ! check_ns (); ! return make_number ((int) ! ([ns_get_screen (display) frame].size.height/(92.0/25.4))); } ! DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, ! 0, 1, 0, ! doc: /* Return the width of Nextstep display server DISPLAY, in millimeters. ! DISPLAY should be a frame, the display name as a string, or a terminal ID. ! If omitted or nil, the selected frame's display is used. */) ! (Lisp_Object display) { ! check_ns (); ! return make_number ((int) ! ([ns_get_screen (display) frame].size.width/(92.0/25.4))); } --- 1700,1728 ---- } ! DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0, ! doc: /* Return the height in millimeters of the Nextstep display TERMINAL. ! The optional argument TERMINAL specifies which display to ask about. ! TERMINAL should be a terminal object, a frame or a display name (a string). ! If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object terminal) { ! struct ns_display_info *dpyinfo = check_ns_display_info (terminal); ! ! return make_number ((int) (x_display_pixel_height (dpyinfo) / (92.0/25.4))); } ! DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, ! doc: /* Return the width in millimeters of the Nextstep display TERMINAL. ! The optional argument TERMINAL specifies which display to ask about. ! TERMINAL should be a terminal object, a frame or a display name (a string). ! If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object terminal) { ! struct ns_display_info *dpyinfo = check_ns_display_info (terminal); ! ! return make_number ((int) (x_display_pixel_width (dpyinfo) / (92.0/25.4))); } *************** *** 1751,1766 **** DEFUN ("x-display-visual-class", Fx_display_visual_class, Sx_display_visual_class, 0, 1, 0, ! doc: /* Return the visual class of the Nextstep display server DISPLAY. The value is one of the symbols `static-gray', `gray-scale', `static-color', `pseudo-color', `true-color', or `direct-color'. ! DISPLAY should be a frame, the display name as a string, or a terminal ID. ! If omitted or nil, the selected frame's display is used. */) ! (Lisp_Object display) { ! NSWindowDepth depth; ! check_ns (); ! depth = [ns_get_screen (display) depth]; if ( depth == NSBestDepth (NSCalibratedWhiteColorSpace, 2, 2, YES, NULL)) return intern ("static-gray"); --- 1752,1768 ---- DEFUN ("x-display-visual-class", Fx_display_visual_class, Sx_display_visual_class, 0, 1, 0, ! doc: /* Return the visual class of the Nextstep display TERMINAL. The value is one of the symbols `static-gray', `gray-scale', `static-color', `pseudo-color', `true-color', or `direct-color'. ! ! The optional argument TERMINAL specifies which display to ask about. ! TERMINAL should a terminal object, a frame or a display name (a string). ! If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object terminal) { ! struct ns_display_info *dpyinfo = check_ns_display_info (terminal); ! NSWindowDepth depth = [[[NSScreen screens] objectAtIndex:0] depth]; if ( depth == NSBestDepth (NSCalibratedWhiteColorSpace, 2, 2, YES, NULL)) return intern ("static-gray"); *************** *** 2332,2344 **** DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, doc: /* Internal function called by `display-color-p', which see. */) ! (Lisp_Object display) { ! NSWindowDepth depth; ! NSString *colorSpace; ! check_ns (); ! depth = [ns_get_screen (display) depth]; ! colorSpace = NSColorSpaceFromDepth (depth); return [colorSpace isEqualToString: NSDeviceWhiteColorSpace] || [colorSpace isEqualToString: NSCalibratedWhiteColorSpace] --- 2334,2344 ---- DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, doc: /* Internal function called by `display-color-p', which see. */) ! (Lisp_Object terminal) { ! struct ns_display_info *dpyinfo = check_ns_display_info (terminal); ! NSWindowDepth depth = [[[NSScreen screens] objectAtIndex:0] depth]; ! NSString *colorSpace = NSColorSpaceFromDepth (depth); return [colorSpace isEqualToString: NSDeviceWhiteColorSpace] || [colorSpace isEqualToString: NSCalibratedWhiteColorSpace] *************** *** 2346,2363 **** } ! DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, ! Sx_display_grayscale_p, 0, 1, 0, doc: /* Return t if the Nextstep display supports shades of gray. Note that color displays do support shades of gray. ! The optional argument DISPLAY specifies which display to ask about. ! DISPLAY should be either a frame, a display name (a string), or terminal ID. ! If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object display) { ! NSWindowDepth depth; ! check_ns (); ! depth = [ns_get_screen (display) depth]; return NSBitsPerPixelFromDepth (depth) > 1 ? Qt : Qnil; } --- 2346,2362 ---- } ! DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p, ! 0, 1, 0, doc: /* Return t if the Nextstep display supports shades of gray. Note that color displays do support shades of gray. ! The optional argument TERMINAL specifies which display to ask about. ! TERMINAL should be a terminal object, a frame or a display name (a string). ! If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object terminal) { ! struct ns_display_info *dpyinfo = check_ns_display_info (terminal); ! NSWindowDepth depth = [[[NSScreen screens] objectAtIndex:0] depth]; return NSBitsPerPixelFromDepth (depth) > 1 ? Qt : Qnil; } *************** *** 2365,2391 **** DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width, 0, 1, 0, ! doc: /* Return the width in pixels of the Nextstep display DISPLAY. ! The optional argument DISPLAY specifies which display to ask about. ! DISPLAY should be either a frame, a display name (a string), or terminal ID. If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object display) { ! check_ns (); ! return make_number ((int) [ns_get_screen (display) frame].size.width); } DEFUN ("x-display-pixel-height", Fx_display_pixel_height, Sx_display_pixel_height, 0, 1, 0, ! doc: /* Return the height in pixels of the Nextstep display DISPLAY. ! The optional argument DISPLAY specifies which display to ask about. ! DISPLAY should be either a frame, a display name (a string), or terminal ID. If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object display) { ! check_ns (); ! return make_number ((int) [ns_get_screen (display) frame].size.height); } --- 2364,2392 ---- DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width, 0, 1, 0, ! doc: /* Return the width in pixels of the Nextstep display TERMINAL. ! The optional argument TERMINAL specifies which display to ask about. ! TERMINAL should be a terminal object, a frame or a display name (a string). If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object terminal) { ! struct ns_display_info *dpyinfo = check_ns_display_info (terminal); ! ! return make_number (x_display_pixel_width (dpyinfo)); } DEFUN ("x-display-pixel-height", Fx_display_pixel_height, Sx_display_pixel_height, 0, 1, 0, ! doc: /* Return the height in pixels of the Nextstep display TERMINAL. ! The optional argument TERMINAL specifies which display to ask about. ! TERMINAL should be a terminal object, a frame or a display name (a string). If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object terminal) { ! struct ns_display_info *dpyinfo = check_ns_display_info (terminal); ! ! return make_number (x_display_pixel_height (dpyinfo)); } *************** *** 2422,2436 **** DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes, 0, 1, 0, ! doc: /* Return the number of bitplanes of the Nextstep display DISPLAY. ! The optional argument DISPLAY specifies which display to ask about. ! DISPLAY should be either a frame, a display name (a string), or terminal ID. If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object display) { ! check_ns (); return make_number ! (NSBitsPerPixelFromDepth ([ns_get_screen (display) depth])); } --- 2423,2438 ---- DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes, 0, 1, 0, ! doc: /* Return the number of bitplanes of the Nextstep display TERMINAL. ! The optional argument TERMINAL specifies which display to ask about. ! TERMINAL should be a terminal object, a frame or a display name (a string). If omitted or nil, that stands for the selected frame's display. */) ! (Lisp_Object terminal) { ! struct ns_display_info *dpyinfo = check_ns_display_info (terminal); ! return make_number ! (NSBitsPerPixelFromDepth ([[[NSScreen screens] objectAtIndex:0] depth])); } === modified file 'src/nsterm.m' *** src/nsterm.m 2013-03-16 14:22:37 +0000 --- src/nsterm.m 2013-03-21 22:55:46 +0000 *************** *** 3813,3827 **** int x_display_pixel_height (struct ns_display_info *dpyinfo) { ! NSScreen *screen = [NSScreen mainScreen]; ! return [screen frame].size.height; } int x_display_pixel_width (struct ns_display_info *dpyinfo) { ! NSScreen *screen = [NSScreen mainScreen]; ! return [screen frame].size.width; } --- 3813,3843 ---- int x_display_pixel_height (struct ns_display_info *dpyinfo) { ! NSArray *screens = [NSScreen screens]; ! NSEnumerator *enumerator = [screens objectEnumerator]; ! NSScreen *screen; ! NSRect frame; ! ! frame = NSZeroRect; ! while ((screen = [enumerator nextObject]) != nil) ! frame = NSUnionRect (frame, [screen frame]); ! ! return NSHeight (frame); } int x_display_pixel_width (struct ns_display_info *dpyinfo) { ! NSArray *screens = [NSScreen screens]; ! NSEnumerator *enumerator = [screens objectEnumerator]; ! NSScreen *screen; ! NSRect frame; ! ! frame = NSZeroRect; ! while ((screen = [enumerator nextObject]) != nil) ! frame = NSUnionRect (frame, [screen frame]); ! ! return NSWidth (frame); } === modified file 'src/w32fns.c' *** src/w32fns.c 2013-03-20 11:29:37 +0000 --- src/w32fns.c 2013-03-21 05:20:04 +0000 *************** *** 4731,4745 **** { struct w32_display_info *dpyinfo = check_x_display_info (display); HDC hdc; ! int cap; ! hdc = GetDC (dpyinfo->root_window); ! cap = GetDeviceCaps (hdc, VERTSIZE); ! ! ReleaseDC (dpyinfo->root_window, hdc); ! ! return make_number (cap); } DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, --- 4731,4745 ---- { struct w32_display_info *dpyinfo = check_x_display_info (display); HDC hdc; ! float mm_per_pixel; ! hdc = GetDC (NULL); ! mm_per_pixel = ((float) GetDeviceCaps (hdc, VERTSIZE) ! / GetDeviceCaps (hdc, VERTRES)); ! ReleaseDC (NULL, hdc); ! return make_number ((int) (x_display_pixel_height (dpyinfo) * mm_per_pixel ! + 0.5f)); } DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, *************** *** 4750,4766 **** (Lisp_Object display) { struct w32_display_info *dpyinfo = check_x_display_info (display); - HDC hdc; ! int cap; ! ! hdc = GetDC (dpyinfo->root_window); ! ! cap = GetDeviceCaps (hdc, HORZSIZE); ! ReleaseDC (dpyinfo->root_window, hdc); ! return make_number (cap); } DEFUN ("x-display-backing-store", Fx_display_backing_store, --- 4750,4765 ---- (Lisp_Object display) { struct w32_display_info *dpyinfo = check_x_display_info (display); HDC hdc; ! float mm_per_pixel; ! hdc = GetDC (NULL); ! mm_per_pixel = ((float) GetDeviceCaps (hdc, HORZSIZE) ! / GetDeviceCaps (hdc, HORZRES)); ! ReleaseDC (NULL, hdc); ! return make_number ((int) (x_display_pixel_width (dpyinfo) * mm_per_pixel ! + 0.5f)); } DEFUN ("x-display-backing-store", Fx_display_backing_store, === modified file 'src/w32term.c' *** src/w32term.c 2013-03-15 10:07:29 +0000 --- src/w32term.c 2013-03-21 05:08:16 +0000 *************** *** 142,147 **** --- 142,156 ---- #define WS_EX_LAYERED 0x80000 #endif + /* SM_CXVIRTUALSCREEN and SM_CYVIRTUALSCREEN are not defined on 95 and + NT4. */ + #ifndef SM_CXVIRTUALSCREEN + #define SM_CXVIRTUALSCREEN 78 + #endif + #ifndef SM_CYVIRTUALSCREEN + #define SM_CXVIRTUALSCREEN 79 + #endif + /* This is a frame waiting to be autoraised, within w32_read_socket. */ struct frame *pending_autoraise_frame; *************** *** 515,533 **** int x_display_pixel_height (struct w32_display_info *dpyinfo) { ! HDC dc = GetDC (NULL); ! int pixels = GetDeviceCaps (dc, VERTRES); ! ReleaseDC (NULL, dc); ! return pixels; } int x_display_pixel_width (struct w32_display_info *dpyinfo) { ! HDC dc = GetDC (NULL); ! int pixels = GetDeviceCaps (dc, HORZRES); ! ReleaseDC (NULL, dc); ! return pixels; } --- 524,554 ---- int x_display_pixel_height (struct w32_display_info *dpyinfo) { ! if (!(w32_major_version == 4 && w32_minor_version == 0)) ! return GetSystemMetrics (SM_CYVIRTUALSCREEN); ! else ! { ! /* Windows 95 or NT 4.0 */ ! HDC dc = GetDC (NULL); ! int pixels = GetDeviceCaps (dc, VERTRES); ! ReleaseDC (NULL, dc); ! return pixels; ! } } int x_display_pixel_width (struct w32_display_info *dpyinfo) { ! if (!(w32_major_version == 4 && w32_minor_version == 0)) ! return GetSystemMetrics (SM_CXVIRTUALSCREEN); ! else ! { ! /* Windows 95 or NT 4.0 */ ! HDC dc = GetDC (NULL); ! int pixels = GetDeviceCaps (dc, HORZRES); ! ReleaseDC (NULL, dc); ! return pixels; ! } }