summaryrefslogtreecommitdiff
path: root/libjava/gnu/gcj/xlib/Screen.java
blob: 675ed1b9bd0650f4301b799a39133490947d9113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Copyright (C) 2000  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

package gnu.gcj.xlib;

import gnu.gcj.RawData;

/**
 * A flyweight class that denotes an X11 screen.  Display and screen
 * number is the only data kept by this class.  The real screen
 * structure is stored in the display.  There may exist several
 * objects denoting the same screen.
 *
 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
 */
public final class Screen
{
  static final int UNKNOWN = -1;

  Display display;
  int screenNumber = UNKNOWN;
  RawData structure;
  
  Screen(Display display, RawData screenStructure)
  {
    structure = screenStructure;
    this.display = display;
  }

  public Screen(Display display)
  {
    this(display, display.getDefaultScreenNumber());
  }

  public Screen(Display display, int screenNumber)
  {
    this.display = display;
    this.screenNumber = screenNumber;
    initStructure();
  }

  public final Display getDisplay()
  {
    return display;
  }

  public Window getRootWindow()
  {
    int rootXID = getRootWindowXID();
    return display.getWindow(rootXID);
  }

  public Visual getRootVisual()
  {
    RawData visualStructure = getRootVisualStructure();
    int depth = getRootDepth();
    return new Visual(visualStructure, this, depth);
  }

  private native RawData getRootVisualStructure();

  public native int getRootDepth();
  public native int getRootWindowXID();
  public native int getDefaultColormapXID();

  native void initStructure();

  public Colormap getDefaultColormap()
  {
    return new Colormap(this, getDefaultColormapXID());
  }
  
  public final int getScreenNumber()
  {
    if (screenNumber == UNKNOWN)
      screenNumber = findScreenNumber();
    return screenNumber;
  }

  public native int findScreenNumber();
}