[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] pnetlib/Xsharp Application.cs, 1.3, 1.4 Display.cs
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] pnetlib/Xsharp Application.cs, 1.3, 1.4 Display.cs, 1.16, 1.17 TopLevelWindow.cs, 1.17, 1.18 Xlib.cs.in, 1.22, 1.23 |
Date: |
Wed, 03 Dec 2003 02:32:48 +0000 |
Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv4939/Xsharp
Modified Files:
Application.cs Display.cs TopLevelWindow.cs Xlib.cs.in
Log Message:
Add some more ICCCM hints like WM_LOCALE, WM_CLIENT_MACHINE, WM_COMMAND,
WM_CLASS, etc; fix the behaviour of the "IconicState" hint; add the window
group hint; make the "-iconic", "-name", and "-synchronous" Xt command-line
options work correctly.
Index: TopLevelWindow.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/TopLevelWindow.cs,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** TopLevelWindow.cs 2 Dec 2003 13:06:57 -0000 1.17
--- TopLevelWindow.cs 3 Dec 2003 02:32:46 -0000 1.18
***************
*** 24,27 ****
--- 24,28 ----
using System;
using System.Text;
+ using System.Globalization;
using System.Runtime.InteropServices;
using Xsharp.Types;
***************
*** 144,147 ****
--- 145,167 ----
Xlib.Window handle = GetWidgetHandle();
+ // Make this the group leader if we
don't have one yet.
+ bool isFirst = false;
+ if(dpy.groupLeader == Xlib.Window.Zero)
+ {
+ dpy.groupLeader = handle;
+ isFirst = true;
+ }
+
+ // Set the WM_CLASS hint.
+ Application app = Application.Primary;
+ if(app != null)
+ {
+ XClassHint classHint = new
XClassHint();
+ classHint.res_name =
app.ResourceName;
+ classHint.res_class =
app.ResourceClass;
+ Xlib.XSetClassHint(display,
handle, ref classHint);
+ classHint.Free();
+ }
+
// Set the title bar and icon names.
SetWindowName(display, handle,
this.name);
***************
*** 151,156 ****
--- 171,215 ----
// Set the window hints.
+ if(isFirst && app != null &&
app.StartIconic)
+ {
+ // The user supplied "-iconic"
on the command-line.
+ iconic = true;
+ }
SetWMHints(display, handle);
+ // Set some other string properties.
+ String name =
CultureInfo.CurrentCulture.Name;
+ if(name == null || name == String.Empty)
+ {
+ name = "en_US";
+ }
+ else
+ {
+ name = name.Replace("-", "_");
+ }
+ SetTextProperty(display, handle,
"WM_LOCALE_NAME", name);
+ name = Application.Hostname;
+ if(name != null)
+ {
+ SetTextProperty(display, handle,
+
"WM_CLIENT_MACHINE", name);
+ }
+ if(isFirst)
+ {
+ String[] args =
Environment.GetCommandLineArgs();
+ if(args != null && args.Length
> 0)
+ {
+ // We put "ilrun" at
the start of the command,
+ // because the command
needs to be in a form
+ // that can be directly
executed by fork/exec,
+ // and IL binaries
normally aren't in this form.
+ String[] newArgs = new
String [args.Length + 1];
+ newArgs[0] = "ilrun";
+ Array.Copy(args, 0,
newArgs, 1, args.Length);
+
SetTextProperty(display, handle,
+
"WM_COMMAND", newArgs);
+ }
+ }
+
// Top-level widgets receive all key
and focus events.
SelectInput(EventMask.KeyPressMask |
***************
*** 240,245 ****
{
XWMHints hints = new XWMHints();
! hints.flags = WMHintsMask.InputHint;
hints.input = true;
if(icon != null)
{
--- 299,309 ----
{
XWMHints hints = new XWMHints();
! hints.flags = WMHintsMask.InputHint |
! WMHintsMask.StateHint
|
!
WMHintsMask.WindowGroupHint;
hints.input = true;
+ hints.initial_state = (iconic ?
WindowState.IconicState
+
: WindowState.NormalState);
+ hints.window_group =
(Xlib.XID)(dpy.groupLeader);
if(icon != null)
{
***************
*** 262,265 ****
--- 326,355 ----
}
+ // Set a text property hint on this window.
+ private void SetTextProperty(IntPtr display, Xlib.Window handle,
+ String
property, String value)
+ {
+ XTextProperty textprop = new XTextProperty();
+ if(textprop.SetText(value))
+ {
+ Xlib.XSetTextProperty
+ (display, handle, ref textprop,
+ Xlib.XInternAtom(display,
property, Xlib.Bool.False));
+ textprop.Free();
+ }
+ }
+ private void SetTextProperty(IntPtr display, Xlib.Window handle,
+ String
property, String[] value)
+ {
+ XTextProperty textprop = new XTextProperty();
+ if(textprop.SetText(value))
+ {
+ Xlib.XSetTextProperty
+ (display, handle, ref textprop,
+ Xlib.XInternAtom(display,
property, Xlib.Bool.False));
+ textprop.Free();
+ }
+ }
+
// Construct the XSizeHints structure for this window.
private XSizeHints BuildSizeHints(int x, int y, int width, int height)
***************
*** 469,478 ****
if(!iconic)
{
! // Send an "iconify" message to
the window manager,
! // which will take care of
iconifying the window.
! Xlib.XIconifyWindow
! (display,
GetWidgetHandle(), screen.ScreenNumber);
! iconic = true;
! OnIconicStateChanged(true);
}
}
--- 559,580 ----
if(!iconic)
{
! if(firstMapDone)
! {
! // Send an "iconify"
message to the window manager,
! // which will take care
of iconifying the window.
! Xlib.XIconifyWindow
! (display,
GetWidgetHandle(),
!
screen.ScreenNumber);
! iconic = true;
!
OnIconicStateChanged(true);
! }
! else
! {
! // We haven't been
mapped for the first time yet,
! // so merely update the
WM_HINTS structure.
! iconic = true;
! SetWMHints(display,
GetWidgetHandle());
!
OnIconicStateChanged(true);
! }
}
}
***************
*** 495,500 ****
// Use "XMapRaised" to notify
the window manager
// that we want to be
de-iconified.
- Xlib.XMapRaised(display,
GetWidgetHandle());
iconic = false;
OnIconicStateChanged(false);
if(!mapped)
--- 597,607 ----
// Use "XMapRaised" to notify
the window manager
// that we want to be
de-iconified.
iconic = false;
+ if(!firstMapDone)
+ {
+ // Switch the WM_HINTS
back to say "NormalState".
+ SetWMHints(display,
GetWidgetHandle());
+ }
+ Xlib.XMapRaised(display,
GetWidgetHandle());
OnIconicStateChanged(false);
if(!mapped)
Index: Application.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Application.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Application.cs 21 Jun 2003 11:16:18 -0000 1.3
--- Application.cs 3 Dec 2003 02:32:46 -0000 1.4
***************
*** 24,27 ****
--- 24,29 ----
using System;
using System.Collections;
+ using System.Net;
+ using System.Runtime.InteropServices;
/// <summary>
***************
*** 67,70 ****
--- 69,73 ----
int firstArg = 0;
String fontName;
+ bool synchronous = false;
// Set this as the primary application object
if necessary.
***************
*** 105,109 ****
if(index != -1)
{
! name =
programName.Substring(index);
}
else
--- 108,112 ----
if(index != -1)
{
! name =
programName.Substring(index + 1);
}
else
***************
*** 111,114 ****
--- 114,125 ----
name = programName;
}
+ int len = name.Length;
+ if(len > 4 && name[len - 4] == '.' &&
+ (name[len - 3] == 'e' || name[len -
3] == 'E') &&
+ (name[len - 2] == 'x' || name[len -
2] == 'X') &&
+ (name[len - 1] == 'e' || name[len -
1] == 'E'))
+ {
+ name = name.Substring(0, len -
4);
+ }
}
if(args == null)
***************
*** 176,201 ****
break;
- case "-bg":
- case "-background":
- {
- ++firstArg;
- if(firstArg <
args.Length)
- {
- // TODO: set
the application's background color.
- }
- }
- break;
-
- case "-fg":
- case "-foreground":
- {
- ++firstArg;
- if(firstArg <
args.Length)
- {
- // TODO: set
the application's foreground color.
- }
- }
- break;
-
case "-fn":
case "-font":
--- 187,190 ----
***************
*** 214,222 ****
if(firstArg <
args.Length)
{
! title =
args[firstArg];
}
}
break;
// Ignore other Xt toolkit
options that aren't
// relevant to us. We may add
some of these later.
--- 203,219 ----
if(firstArg <
args.Length)
{
! geometry =
args[firstArg];
}
}
break;
+ case "+synchronous":
+ case "-synchronous":
+ {
+ // Turn on synchronous
processing to the X server.
+ synchronous = true;
+ }
+ break;
+
// Ignore other Xt toolkit
options that aren't
// relevant to us. We may add
some of these later.
***************
*** 224,234 ****
case "-rv":
case "+rv":
- case "+synchronous":
- case "-synchronous":
break;
case "-bw":
case "-borderwidth":
case "-bd":
case "-bordercolor":
case "-selectionTimeout":
case "-xnllanguage":
--- 221,233 ----
case "-rv":
case "+rv":
break;
+ case "-bg":
+ case "-background":
case "-bw":
case "-borderwidth":
case "-bd":
case "-bordercolor":
+ case "-fg":
+ case "-foreground":
case "-selectionTimeout":
case "-xnllanguage":
***************
*** 250,254 ****
// Connect to the display.
! display = Xsharp.Display.Open(displayName,
this);
// Create the default font.
--- 249,253 ----
// Connect to the display.
! display = Xsharp.Display.Open(displayName,
this, synchronous);
// Create the default font.
***************
*** 522,525 ****
--- 521,571 ----
{
return primary;
+ }
+ }
+
+ /// <summary>
+ /// <para>Get the name of the host that this program is running
on.</para>
+ /// </summary>
+ ///
+ /// <value>
+ /// <para>The host name.</para>
+ /// </value>
+ public static String Hostname
+ {
+ get
+ {
+ // Get the hostname via "_XGetHostname"
in "Xlib".
+ IntPtr buf = Marshal.AllocHGlobal(1024);
+ if(buf == IntPtr.Zero)
+ {
+ return null;
+ }
+ Xlib._XGetHostname(buf, 1024);
+ String host =
Marshal.PtrToStringAnsi(buf);
+ Marshal.FreeHGlobal(buf);
+ if(host == null || host == String.Empty)
+ {
+ return null;
+ }
+
+ #if false
+ // TODO: DNS routines are a little
flaky at present.
+
+ // Fully-qualify the name, if possible.
+ if(host.IndexOf('.') != -1)
+ {
+ return null;
+ }
+ IPHostEntry entry = Dns.Resolve(host);
+ if(entry == null)
+ {
+ return host;
+ }
+ else
+ {
+ return entry.HostName;
+ }
+ #endif
+ return host;
}
}
Index: Xlib.cs.in
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Xlib.cs.in,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** Xlib.cs.in 2 Dec 2003 13:06:57 -0000 1.22
--- Xlib.cs.in 3 Dec 2003 02:32:46 -0000 1.23
***************
*** 96,99 ****
--- 96,102 ----
extern public static @X_long@ XMaxRequestSize(IntPtr display);
+ [DllImport("X11")]
+ extern public static IntPtr XSynchronize(IntPtr display, Xlib.Bool
onoff);
+
// Declare screen-related external functions.
***************
*** 482,485 ****
--- 485,492 ----
[DllImport("X11")]
+ extern public static void XSetClassHint
+ (IntPtr display, Window w, ref XClassHint class_hints);
+
+ [DllImport("X11")]
extern public static @X_int@ XKillClient(IntPtr display, XID resource);
***************
*** 528,531 ****
--- 535,559 ----
extern public static @X_int@ XDeleteProperty
(IntPtr display, Window w, Atom property);
+
+ // Text property and string functions.
+
+ [DllImport("X11")]
+ extern public static @X_int@ XFree(IntPtr ptr);
+
+ [DllImport("X11")]
+ extern public static Status XStringListToTextProperty
+ (ref IntPtr argv, @X_int@ argc, ref XTextProperty
textprop);
+
+ [DllImport("X11")]
+ extern public static Status XStringListToTextProperty
+ (IntPtr[] argv, @X_int@ argc, ref XTextProperty
textprop);
+
+ [DllImport("X11")]
+ extern public static void XSetTextProperty
+ (IntPtr display, Window w, ref XTextProperty textProp,
+ Atom property);
+
+ [DllImport("X11")]
+ extern public static @X_int@ _XGetHostname(IntPtr buf, @X_int@ maxlen);
// Helper functions from "libXsharpSupport.so".
Index: Display.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/Display.cs,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** Display.cs 2 Dec 2003 07:28:06 -0000 1.16
--- Display.cs 3 Dec 2003 02:32:46 -0000 1.17
***************
*** 61,64 ****
--- 61,65 ----
internal Timer timerQueue;
internal IntPtr imlibData;
+ internal Xlib.Window groupLeader;
// Constructor.
***************
*** 148,152 ****
// Internal version of "Open()" that is called once the
// type lock has been acquired.
! private static Display OpenInternal(String displayName, Application app)
{
try
--- 149,154 ----
// Internal version of "Open()" that is called once the
// type lock has been acquired.
! private static Display OpenInternal
! (String displayName, Application app, bool sync)
{
try
***************
*** 187,190 ****
--- 189,196 ----
{
// We have opened the display
successfully.
+ if(sync)
+ {
+ Xlib.XSynchronize(dpy,
Xlib.Bool.True);
+ }
return new Display(dpy,
displayName, app);
}
***************
*** 226,234 ****
// Open a connection to a specific X display server.
! internal static Display Open(String displayName, Application app)
{
lock(typeof(Display))
{
! return OpenInternal(displayName, app);
}
}
--- 232,240 ----
// Open a connection to a specific X display server.
! internal static Display Open(String displayName, Application app, bool
sync)
{
lock(typeof(Display))
{
! return OpenInternal(displayName, app,
sync);
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] pnetlib/Xsharp Application.cs, 1.3, 1.4 Display.cs, 1.16, 1.17 TopLevelWindow.cs, 1.17, 1.18 Xlib.cs.in, 1.22, 1.23,
Rhys Weatherley <address@hidden> <=