El siguiente código es un ejemplo simple del uso de los recursos externos del API de X11.
Sólo funciona con sistemas de 64 bits.
El presente código es la traducción a Gambas con variaciones y integraciones, del código original, escrito en lenguaje C, del proyecto de Kjetil Erga, llamado: "Xlib Calculator ".
Sólo funciona con sistemas de 64 bits.
El presente código es la traducción a Gambas con variaciones y integraciones, del código original, escrito en lenguaje C, del proyecto de Kjetil Erga, llamado: "Xlib Calculator ".
GAMBAS
-
-
- Library "libX11:6.3.0"
-
-
- FocusIn, FocusOut, KeymapNotify, Expose, GraphicsExpose, NoExpose
-
- ' Display *XOpenDisplay(char *display_name)
- ' Opens a connection to the X server that controls a display.
-
- ' int XDefaultScreen(Display *display)
- ' Return the default screen number referenced by the XOpenDisplay() function.
-
- ' Window XRootWindow(Display *display, int screen_number)
- ' Return the root window for the default screen.
-
- ' Window XCreateSimpleWindow(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, unsigned long border, unsigned long background)
- ' creates an unmapped InputOutput subwindow for a specified parent window, returns the window ID of the created window.
-
- ' XSelectInput (Display *display, Window w, long event_mask)
- ' requests that the X server report the events associated with the specified Event mask.
-
- ' XMapRaised (Display *display, Window w)
- ' raises the specified window to the top of the stack.
-
- ' Atom XInternAtom(Display *display, char *atom_name, Bool only_if_exists)
- ' Returns the atom identifier associated with the specified atom_name string.
-
- ' Status XSetWMProtocols(Display *display, Window w, Atom *protocols, int count)
- ' Replaces the WM_PROTOCOLS property on the specified window with the list of atoms specified by the protocols argument.
-
- ' XNextEvent (Display *display, XEvent *event_return)
- ' gets the next event and remove it from the queue
-
- ' KeySym XkbKeycodeToKeysym (Display *dpy, KeyCode kc, unsigned int group, unsigned int level)
- ' Returns the keysym bound to a particular group and shift level for a particular key on the core keyboard.
-
- ' Status XSendEvent(Display *display, Window w, Bool propagate, long event_mask, XEvent *event_send)
- ' Identifies the destination window, determines which clients should receive the specified events.
-
- ' Status XGetWindowAttributes(Display *display, Window w, XWindowAttributes *window_attributes_return)
- ' Returns the current attributes for the specified window to an XWindowAttributes structure.
-
- ' GC XDefaultGC(Display *display, int screen_number)
- ' Returns the default graphics context for the root window of the specified screen.
-
- ' int XClearArea(Display *display, Window w, int x, int y, unsigned int width, unsigned int height, Bool exposures)
- ' Paints a rectangular area in the specified window.
-
- ' int XDrawRectangle(Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height)
- ' Draw the outlines of the specified rectangle.
-
- ' int XDrawString(Display *display, Drawable d, GC gc, int x, int y, char *string, int length)
- ' Treats each character image as an additional mask for a fill operation on the drawable.
-
- ' XDestroyWindow(Display *display, Window w)
- ' destroys the specified window as well as all of its subwindows
-
- ' XCloseDisplay(Display *display)
- ' Closes the connection to the X server for the display specified in the Display structure and destroys all windows.
-
-
-
-
- ' Apre la connessione con il server display del sistema grafico X:
- disp = XOpenDisplay(0)
-
- scr = XDefaultScreen(disp)
-
- ' Crea la finestra secondo i parametri previsti dalla funzione. L'ultimo parametro imposta il colore di fondo della finestra:
- id = XCreateSimpleWindow(disp, XRootWindow(disp, scr), 0, 0, 200, 300, 0, 0, &FFEFDF)
-
- ' Dice al server display quali eventi deve vedere:
-
- ' Apre la finestra sullo schermo. Si può utilizzare anche la funzione "XMapWindow(display, w)":
- XMapRaised(disp, id)
-
-
-
- ' Alloca un'area di memoria pari alla Struttura esterna 'XEvent' (192 byte):
-
- ' Inizia il ciclo, restando in attesa di un evento stabilito con la precedente funzione XSelectInput():
-
- XNextEvent(disp, ev)
-
- ' Se viene premuta la X nell'angolo alto a destra, chiude la finestra:
- Case ClientMessage
- Case Expose
- DisegnaCalc(disp, id, scr)
- Case KeyPress
- ' Se viene premuto il tasto "q" della tastiera, la finestra viene chiusa:
- Calcolo(ks)
- ' Ridisegna la finestra:
- st.Close
- Case ButtonPress
- st.Close
-
-
-
- ' Chiude la finestra e libera la memoria:
- XDestroyWindow(disp, id)
- XCloseDisplay(disp)
-
-
-
-
-
-
- ' Alloca un'area di memoria pari alla Struttura esterna 'XWindowAttributes' (192 byte):
-
- gc = XDefaultGC(dis, sc)
-
- XDrawString(dis, idW, gc, 30, 30, buf, buf_len)
-
-
-
-
-
-
-
- valore_mostrato = 0.0
- valore_buffer = 0.0
- modo_decimale = 0
- operazione = 0
- disp_mod = 0
- valore_mostrato = 0.0
- disp_mod = 0
- Inc modo_decimale
- valore_mostrato *= 10
- valore_mostrato += (lo - &30)
- Case 42
- valore_mostrato = valore_buffer * valore_mostrato
- Case 43
- valore_mostrato = valore_buffer + valore_mostrato
- Case 45
- valore_mostrato = valore_buffer - valore_mostrato
- Case 47
- valore_mostrato = valore_buffer / valore_mostrato
- valore_buffer = valore_mostrato
- operazione = lo
- disp_mod = 1
- modo_decimale = 0
- Case 42
- valore_mostrato = valore_buffer * valore_mostrato
- Case 43
- valore_mostrato = valore_buffer + valore_mostrato
- Case 45
- valore_mostrato = valore_buffer - valore_mostrato
- Case 47
- valore_mostrato = valore_buffer / valore_mostrato
- operazione = 0
- disp_mod = 1
- modo_decimale = 0
-
-
-
-
- Return i ^ n
-
-
-
-
-
-
-
-
-
"Los horizontes perdidos nunca regresan. " (F. Battiato, La stagione dell'amore, 1983)
"Las ondas nunca regresan. " (Genesis: Ripples - A trick of the tail, 1976)