Re: detect current Xwindow Resolution?



Hi,

> See functions declared in 
> 	/usr/X11R6/include/X11/extensions/xf86vmode.h

Yes you can use the vidmode extension to apply new modeline
timings for the current modeline and you can switch withing the
pool of defined resolutions. The mode switch works only if your
XF86Config provides all the resolutions you want to use

> >    I appreciate someone who is helping me to investigate 
> > how to change the resolution through the coding, However, 
> > I also whondering if someone who knows how to detect
> > the current XWindow resolution by writing a code?

Here is a small example how to obtain the current 
resolution. The XF86VidModeGetModeLine() function is used to do 
this... there are some man pages on this topic too:

---snip---

#include <stdlib.h>
#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>
#include <X11/Xatom.h>
#include <X11/Xmu/StdSel.h>
#include <X11/Xmd.h>
#include <X11/extensions/xf86vmode.h>

//=======================================
// Prototypes...
//---------------------------------------
Display* XOpen(char name[256]);

//=======================================
// Globals...
//---------------------------------------
int MajorVersion, MinorVersion;
int EventBase, ErrorBase;

int main(void) {
 XF86VidModeModeLine mode_line;
 int dot_clock;
 Display* dpy;

 // open display
 dpy = XOpen("null");

 // query modeline
 if (!XF86VidModeGetModeLine (dpy,DefaultScreen(dpy),&dot_clock,&mode_line)) {
  fprintf(stderr,"XF86VidModeGetModeLine: could not get modeline timings\n");
  XCloseDisplay(dpy);
  exit(1);
 }

 printf("%dx%d\n",mode_line.hdisplay,mode_line.vdisplay);
 XCloseDisplay(dpy);
 exit(0);
}

//=======================================
// open display, prepare vidmode ext...
//---------------------------------------
Display* XOpen(char name[256]) {
 Display *dpy;
 char display[256] = "";

 if (strcmp(name,"null") == 0) {
  strcpy(display,getenv("DISPLAY"));
 } else {
  strcpy(display,name);
 }
 if(!(dpy = XOpenDisplay(display))) {
  fprintf (stderr, "unable to open display: %s\n",getenv("DISPLAY"));
  return(NULL);
 }
 if (!XF86VidModeQueryVersion(dpy, &MajorVersion, &MinorVersion)) {
  fprintf (stderr, "Unable to query video extension version\n");
  return(NULL);
 }
 if (!XF86VidModeQueryExtension(dpy, &EventBase, &ErrorBase)) {
  fprintf (stderr, "Unable to query video extension information\n");
  return(NULL);
 }
 return(dpy);
}

---snap-- 

compile with:

 gcc res.c -o res -lX11 -lXxf86vm -lXext -L/usr/X11R6/lib

cu
Marcus




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]