Difference between revisions of "X11"

From Lazarus wiki
(New page: The X11 package contains some units which contain the translations of the X header files. The following files exist: * '''X''' basic X routines. * '''xcms''' Some color management. * '''x...)
 
(Fixed syntax highlighting; fixed typos; deleted categories included in page template)
 
(7 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The X11 package contains some units which contain the translations of the X header files. The following files exist:
+
{{X11}}
 +
 
 +
The X11 package contains some units which contain the translations of the X header files.
 +
__TOC__
 +
==List of units==
 +
The most basic units are:
  
 
* '''X''' basic X routines.
 
* '''X''' basic X routines.
Line 26: Line 31:
 
All these units link to the various X libraries. These units interface to the documented client libraries, and are thus largely immune to the X11<->Xorg changes.
 
All these units link to the various X libraries. These units interface to the documented client libraries, and are thus largely immune to the X11<->Xorg changes.
  
Go to back [[Package_List|Packages List]]
+
==Examples==
 +
 
 +
===A window with a message===
 +
 
 +
This is a very simple application which shows a window with a written message.
 +
 
 +
<syntaxhighlight lang=pascal>
 +
program xshowwindow;
 +
 
 +
{$mode objfpc}{$H+}
 +
 
 +
uses
 +
  xlib,
 +
  x,
 +
  ctypes;
 +
 
 +
procedure ModalShowX11Window(AMsg: string);
 +
var
 +
  d: PDisplay;
 +
  w: TWindow;
 +
  e: TXEvent;
 +
  msg: PChar;
 +
  s: cint;
 +
begin
 +
  msg := PChar(AMsg);
 +
 
 +
  { open connection with the server }
 +
  d := XOpenDisplay(nil);
 +
  if (d = nil) then
 +
  begin
 +
    WriteLn('[ModalShowX11Window] Cannot open display');
 +
    exit;
 +
  end;
 +
 
 +
  s := DefaultScreen(d);
 +
 
 +
  { create window }
 +
  w := XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 200, 200, 1,
 +
                          BlackPixel(d, s), WhitePixel(d, s));
 +
 
 +
  { select kind of events we are interested in }
 +
  XSelectInput(d, w, ExposureMask or KeyPressMask);
 +
 
 +
  { map (show) the window }
 +
  XMapWindow(d, w);
 +
 
 +
  { event loop }
 +
  while (True) do
 +
  begin
 +
    XNextEvent(d, @e);
 +
    { draw or redraw the window }
 +
    if (e._type = Expose) then
 +
    begin
 +
      XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
 +
      XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg));
 +
    end;
 +
    { exit on key press }
 +
    if (e._type = KeyPress) then Break;
 +
  end;
 +
 
 +
  { close connection to server }
 +
  XCloseDisplay(d);
 +
end;
 +
 
 +
begin
 +
  ModalShowX11Window('My message');
 +
end.
 +
</syntaxhighlight>
 +
 
 +
==See Also==
 +
 
 +
* http://en.wikipedia.org/wiki/Xlib

Latest revision as of 03:33, 21 December 2019

Deutsch (de) English (en) español (es)

The X11 package contains some units which contain the translations of the X header files.

List of units

The most basic units are:

  • X basic X routines.
  • xcms Some color management.
  • xlib Xlib toolkit.
  • xrender X Render extension.
  • xresource X resource management.
  • xshm X shared memory extension.
  • xutil X util lib.

Newer units:

  • cursorfont
  • xinerama
  • xrandr
  • keysym
  • xf86dga.pp
  • xkb
  • xv
  • xf86vmode
  • xkblib
  • xvlib
  • xatom
  • xi

All these units link to the various X libraries. These units interface to the documented client libraries, and are thus largely immune to the X11<->Xorg changes.

Examples

A window with a message

This is a very simple application which shows a window with a written message.

program xshowwindow;

{$mode objfpc}{$H+}

uses
  xlib, 
  x,
  ctypes;

procedure ModalShowX11Window(AMsg: string);
var
  d: PDisplay;
  w: TWindow;
  e: TXEvent;
  msg: PChar;
  s: cint;
begin
  msg := PChar(AMsg);

  { open connection with the server }
  d := XOpenDisplay(nil);
  if (d = nil) then
  begin
    WriteLn('[ModalShowX11Window] Cannot open display');
    exit;
  end;

  s := DefaultScreen(d);

  { create window }
  w := XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 200, 200, 1,
                           BlackPixel(d, s), WhitePixel(d, s));

  { select kind of events we are interested in }
  XSelectInput(d, w, ExposureMask or KeyPressMask);

  { map (show) the window }
  XMapWindow(d, w);

  { event loop }
  while (True) do
  begin
    XNextEvent(d, @e);
    { draw or redraw the window }
    if (e._type = Expose) then
    begin
      XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
      XDrawString(d, w, DefaultGC(d, s), 50, 50, msg, strlen(msg));
    end;
    { exit on key press }
    if (e._type = KeyPress) then Break;
  end;

  { close connection to server }
  XCloseDisplay(d);
end;

begin
  ModalShowX11Window('My message');
end.

See Also