-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.x] New: Detect display scaling, cleanup in X11 API #1324
base: 3.x
Are you sure you want to change the base?
Changes from 1 commit
611dd43
1f85448
d12f983
c06c09b
53757be
7d07dc8
f126c1c
b9aefc6
6dba93a
1aa63de
89667c9
ba2eca1
cea70ba
de7b5e2
ea6b602
a88ead0
3fd372d
7ed18a5
5027de0
cca1899
f888461
3fd9fd6
3ca519d
8b659af
12c055e
3cfc0ac
6c5a11f
ccbbebb
865aa26
79a7e44
2df7072
dd83ed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,10 +108,8 @@ internal sealed class X11GLNative : NativeWindowBase | |
private static readonly IntPtr _atom_add = (IntPtr)1; | ||
private static readonly IntPtr _atom_toggle = (IntPtr)2; | ||
|
||
#pragma warning disable 649 // never assigned, compiler bug in Mono 3.4.0 | ||
private Rectangle bounds; | ||
private Size client_size; | ||
#pragma warning restore 649 | ||
private int border_left, border_right, border_top, border_bottom; | ||
private Icon icon; | ||
private bool has_focus; | ||
|
@@ -148,7 +146,6 @@ internal sealed class X11GLNative : NativeWindowBase | |
private readonly IntPtr EmptyCursor; | ||
|
||
#pragma warning disable 414 // Field assigned but never used, we do that on purpose | ||
private readonly bool xi2_supported; | ||
private readonly int xi2_opcode; | ||
private readonly int xi2_version; | ||
#pragma warning restore 414 | ||
|
@@ -258,7 +255,7 @@ public X11GLNative(int x, int y, int width, int height, string title, | |
Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints); | ||
|
||
// Register for window destroy notification | ||
Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { _atom_wm_destroy }, 1); | ||
Functions.XSetWMProtocols(window.Display, window.Handle, new[] { _atom_wm_destroy }, 1); | ||
Comment on lines
-261
to
+258
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can keep the type of the array here. |
||
|
||
// Set the window class hints | ||
Functions.XSetClassHint(window.Display, window.Handle, ref class_hint); | ||
|
@@ -295,7 +292,7 @@ public X11GLNative(int x, int y, int width, int height, string title, | |
|
||
// The XInput2 extension makes keyboard and mouse handling much easier. | ||
// Check whether it is available. | ||
xi2_supported = XI2MouseKeyboard.IsSupported(window.Display); | ||
bool xi2_supported = XI2MouseKeyboard.IsSupported(window.Display); | ||
if (xi2_supported) | ||
{ | ||
xi2_opcode = XI2MouseKeyboard.XIOpCode; | ||
|
@@ -348,16 +345,17 @@ public X11GLNative() | |
} | ||
} | ||
|
||
private void ReadProperty(IntPtr window, IntPtr property, IntPtr type, ref IntPtr data, ref IntPtr itemsCount) | ||
private void ReadProperty(IntPtr targetWindow, IntPtr property, IntPtr type, ref IntPtr data, out int itemsCount) | ||
{ | ||
int format; | ||
IntPtr length = new IntPtr(int.MaxValue); | ||
IntPtr actualType; | ||
IntPtr bytesLeft; | ||
|
||
Functions.XGetWindowProperty(this.window.Display, window, property, IntPtr.Zero, | ||
IntPtr itemCount; | ||
Functions.XGetWindowProperty(this.window.Display, targetWindow, property, IntPtr.Zero, | ||
length, false, type, | ||
out actualType, out format, out itemsCount, out bytesLeft, ref data); | ||
out actualType, out format, out itemCount, out bytesLeft, ref data); | ||
itemsCount = itemCount.ToInt32(); | ||
} | ||
|
||
private string[] parseUriList(string rawString) | ||
|
@@ -854,9 +852,7 @@ public override void ProcessEvents() | |
int formatCount; | ||
if (useList) | ||
{ | ||
IntPtr count = IntPtr.Zero; | ||
ReadProperty(sourceHandler, _atom_xdnd_type_list, (IntPtr)AtomName.XA_ATOM, ref formats, ref count); | ||
formatCount = count.ToInt32(); | ||
ReadProperty(sourceHandler, _atom_xdnd_type_list, (IntPtr)AtomName.XA_ATOM, ref formats, out formatCount); | ||
} | ||
else | ||
{ | ||
|
@@ -946,10 +942,6 @@ public override void ProcessEvents() | |
} | ||
} | ||
} | ||
else if (e.ClientMessageEvent.message_type == _atom_xdnd_leave) | ||
{ | ||
break; | ||
} | ||
Comment on lines
-1011
to
-1014
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove this code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have to go back and check, but IIRC it can never be true from here. |
||
break; | ||
|
||
case XEventName.DestroyNotify: | ||
|
@@ -983,8 +975,7 @@ public override void ProcessEvents() | |
{ | ||
// Translate XKeyPress to characters and | ||
// raise KeyPress events | ||
int status = 0; | ||
status = Functions.XLookupString( | ||
int status = Functions.XLookupString( | ||
ref e.KeyEvent, ascii, ascii.Length, null, IntPtr.Zero); | ||
Encoding.Default.GetChars(ascii, 0, status, chars, 0); | ||
|
||
|
@@ -1109,23 +1100,18 @@ public override void ProcessEvents() | |
break; | ||
|
||
case XEventName.PropertyNotify: | ||
if (e.PropertyEvent.atom == _atom_net_wm_state) | ||
{ | ||
OnWindowStateChanged(EventArgs.Empty); | ||
} | ||
|
||
//if (e.PropertyEvent.atom == _atom_net_frame_extents) | ||
//{ | ||
// RefreshWindowBorders(); | ||
//} | ||
break; | ||
if (e.PropertyEvent.atom == _atom_net_wm_state) | ||
{ | ||
OnWindowStateChanged(EventArgs.Empty); | ||
} | ||
break; | ||
|
||
case XEventName.SelectionNotify: | ||
if (e.SelectionEvent.property == _atom_xdnd_primary) | ||
{ | ||
IntPtr data = IntPtr.Zero; | ||
IntPtr count = IntPtr.Zero; | ||
ReadProperty(e.SelectionEvent.requestor, e.SelectionEvent.property, e.SelectionEvent.target, ref data, ref count); | ||
int count; | ||
ReadProperty(e.SelectionEvent.requestor, e.SelectionEvent.property, e.SelectionEvent.target, ref data, out count); | ||
|
||
string rawString = Marshal.PtrToStringAnsi(data); | ||
Functions.XFree(data); | ||
|
@@ -1345,7 +1331,7 @@ public override OpenTK.WindowState WindowState | |
{ | ||
for (int i = 0; i < (long)nitems; i++) | ||
{ | ||
atom = (IntPtr)Marshal.ReadIntPtr(prop, i * IntPtr.Size); | ||
atom = Marshal.ReadIntPtr(prop, i * IntPtr.Size); | ||
|
||
if (atom == _atom_net_wm_state_maximized_horizontal || | ||
atom == _atom_net_wm_state_maximized_vertical) | ||
|
@@ -1699,7 +1685,6 @@ public IntPtr Handle | |
} | ||
|
||
/// <summary> | ||
/// TODO: Use atoms for this property. | ||
/// Gets or sets the GameWindow title. | ||
/// </summary> | ||
public override string Title | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this field removed and not the others here? To me it would only make sense to keep the all or remove them all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually use the version number itself here:
opentk/src/OpenTK/Platform/X11/X11GLNative.cs
Line 1017 in 3cfc0ac
As the opcode is technically part of the version number string, keeping it seemed logical too. Left the pragma there to suppress the fact we don't use it.
Could probably re-hack slightly to use the underlying variable this refers to inside the X11 mouse / keyboard driver, but that's heading towards the re-write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think we could keep this field, it's unnecessary to remove it.
If we are really unlucky someone uses reflection to read the value of this variable.