source: branches/uq/lang/tcl/src/RpScreenSize.c @ 5315

Last change on this file since 5315 was 5315, checked in by mmh, 9 years ago

fix ScreenSize? bug and support multiple UQ runs with different UQ params

File size: 2.5 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  Rappture::ScreenSize
4 *
5 *  TK doesn't know how to read the screen size properly, so until
6 *  it gets fixed, Rappture can get the correct size using this.
7 * ======================================================================
8 *  AUTHOR:  Martin Hunt, Purdue University
9 *  Copyright (c) 2015  HUBzero Foundation, LLC
10 *
11 *  See the file "license.terms" for information on usage and
12 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * ======================================================================
14 */
15#include "config.h"
16#include <tcl.h>
17#include <stdlib.h>
18#include <stddef.h>
19#include <string.h>
20#include <stdio.h>
21#include <X11/extensions/Xrandr.h>
22
23static Tcl_CmdProc RpScreenSizeCmd;
24
25/*
26 * ------------------------------------------------------------------------
27 *  RpScreenSize_Init()
28 *
29 *  Called in Rappture_Init() to initialize the commands defined
30 *  in this file.
31 * ------------------------------------------------------------------------
32 */
33int
34RpScreenSize_Init(interp)
35    Tcl_Interp *interp;  /* interpreter being initialized */
36{
37    /* install the sysinfo command */
38    Tcl_CreateCommand(interp, "::Rappture::ScreenSize", RpScreenSizeCmd,
39        (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
40    return TCL_OK;
41}
42
43/*
44 * ------------------------------------------------------------------------
45 *  RpScreenSizeCmd()
46 *
47 *  Gets the screen width and height of the default DISPLAY
48 *
49 *  Returns TCL_OK on success, and TCL_ERROR (along with an error
50 *  message in the interpreter) if anything goes wrong.
51 * ------------------------------------------------------------------------
52 */
53static int
54RpScreenSizeCmd(cdata, interp, argc, argv)
55    ClientData cdata;         /* not used */
56    Tcl_Interp *interp;       /* interpreter handling this request */
57    int argc;                 /* number of command line args */
58    CONST84 char *argv[];     /* strings for command line args */
59{
60    Tcl_Obj *resultPtr;
61    int w, h, screen;
62
63    resultPtr = Tcl_GetObjResult(interp);
64
65    Display *dpy = XOpenDisplay(NULL);
66    if (dpy == NULL) {
67        Tcl_AppendResult(interp,
68                "Could not open the display.", (char*)NULL);
69        return TCL_ERROR;
70    }
71    screen = DefaultScreen(dpy);
72
73    w = DisplayWidth(dpy, screen);
74    Tcl_ListObjAppendElement(interp, resultPtr, Tcl_NewIntObj(w));
75
76    h = DisplayHeight(dpy, screen);
77    Tcl_ListObjAppendElement(interp, resultPtr, Tcl_NewIntObj(h));
78
79    XCloseDisplay(dpy);
80    return TCL_OK;
81}
Note: See TracBrowser for help on using the repository browser.