From: Axel S. <Axe...@en...> - 2007-11-20 17:49:43
|
Hi Bit, On Tue, 2007-11-20 at 19:33 +0200, Bit Connor wrote: > > Applied. Thanks for the good documentation. One question about the > > functions that get the screen width and height in pixels: Don't these > > functions take a display (which we haven't bound yet)? > > These functions do not take a display. They all have the same prototype: > > gint gdk_screen_width(void); > > You can see for yourself in the header gdk/gdk.h or in the online docs: > > http://www.gtk.org/api/2.6/gdk/gdk-General.html#gdk-screen-width > > For interested parties, the functions return the dimensions of the > default screen. Here is the source for gdk_screen_width: > > gint > gdk_screen_width (void) > { > return gdk_screen_get_width (gdk_screen_get_default()); > } > > It would be useful to add bindings to GtkDisplay and GtkScreen, for > those who need the added control. Ok, then that's fine then. > Maybe I will even be up to the task. > But first I would like to finish the bindings for GtkCursor. Which > brings me to a question. A while ago someone asked on the gtk2hs-users > mailing list how to change the cursor to an hourglass. The best way to > do this is to use the function gdk_cursor_new to create the hourglass > cursor, with an argument of GDK_WATCH, which is a value of the > GdkCursorType enum. > > My question is what is the best way to do the bindings for the > GdkCursorType enum? > > It looks like: > > typedef enum > { > GDK_X_CURSOR = 0, > GDK_ARROW = 2, > GDK_BASED_ARROW_DOWN = 4, > GDK_BASED_ARROW_UP = 6, > /* ... */ > /* Lots more! */ > /* ... */ > GDK_UR_ANGLE = 148, > GDK_WATCH = 150, > GDK_XTERM = 152, > GDK_LAST_CURSOR, > GDK_CURSOR_IS_PIXMAP = -1 > } GdkCursorType; > > When I tried binding this enum in the same way that all the other > enums are done in gtk2hs, then the resulting haskell type was: > > data CursorType = XCursor | Arrow | BasedArrowDown | BasedArrowUp | > {- lots more -} | UrAngle | Watch | Xterm | LastCursor | > CursorIsPixmap > > These constructors don't seem to fit in with the rest of the gtk2hs > api since they have no namespace-like prefix. I can think of two > alternatives: > > 1. Figure out a way to add a namespace-like prefix to the > constructors, so that instead of XCursor, we will have > CursorTypeXCursor You can do this with c2hs. There are two options: a) you can rename individual values {#enum GdkCursor { GDK_UR_ARROW as CurUrArrow } #} b) you can add a prefix {#enum GdkCursor with prefix = Cur #} You can also use both. The stupid thing is that you can't omit certain values (such as GdkLastCursor and GdkCursorIsPixmap). You could also put this enumeration into a separate module that is not exported by default. The user can then import this module qualified. > 2. Don't have a haskell type for GdkCursorType, and instead use a > string where a GdkCursorType would be used, so that instead of > XCursor, we will have "X_CURSOR", or some other variation. This is > similar to the way gtk2hs works with KeySyms. I think you should not use strings in this case by numeric constants: type Cursor = ...whatever... cursorUrArrow :: Cursor cursorUrArrow = {#const GDK_UR_ARROW #} You might want to look into .../General/Structs.hsc where we use hsc2hs to infer constants like these. I guess it boils down to if the cursor enumeration is extensible. If it is, it's better to define numeric constants since a Haskell enumeration is quite final, unless you add a data Cursor = .. | .. | CurUser Int This solution is a bit unfortunate in this case, as you can't use c2hs to do this for you and you have to define the whole enumeration by hand. I think 2. with constants is the way in this case. Cheers, Axel. |