FullScrren Mode over bash

hi all,

i have a script with starts a programm, but only in window mode.
what can i add that i have directly fullscreen (ctrl+shift+f11) ?

Can you be anymore specific? What is it you want to have happen? Searching these forums for “Maximize” brings a lot of answers from me and others, about binding such an action to a keypress.

– Thomas Adam

Hi,

I’m sorry I cannot tell you how to do it with fvwm-script, but maybe another solution will help you.

Save this code as “win_fullscreen.c”:

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>

#include <stdio.h>
#include <stdlib.h>



int main(int argc, char **argv)
{
     Display *dpy;  

     int windowid;

if(argc<2){
  printf("usage: win_fullscreen WinID\n");
  return(1);
}

        sscanf(argv[1], "%x", &windowid);



   dpy = XOpenDisplay(NULL);
   if (dpy == NULL)
     {
       fprintf(stderr, "Can't open dpy\n");
       return 1;
     }


  XEvent     report;
  Atom       _net_fs, _net_state;
  XEvent     msg;

  _net_state = XInternAtom(dpy, "_NET_WM_STATE", False);
  _net_fs = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);

  printf("fullscreen\n");
  msg.xclient.type = ClientMessage;
  msg.xclient.message_type = _net_state;
  msg.xclient.display = dpy;
  msg.xclient.window = windowid;
  msg.xclient.format = 32;
  msg.xclient.data.l[0] = 2; // toggle
  msg.xclient.data.l[1] = _net_fs;
  msg.xclient.data.l[2] = 0l;
  msg.xclient.data.l[3] = 0l;
  msg.xclient.data.l[4] = 0l;
  XSendEvent(dpy, RootWindow(dpy, 0), False,
	     SubstructureNotifyMask | SubstructureRedirectMask, &msg);
  XFlush(dpy);


XCloseDisplay(dpy);


    return(0);
}

Now compile it:

gcc -lm win_fullscreen.c -owin_fullscreen -I/usr/X11R6/include -L/usr/X11R6/lib -lX11

Now save this as “runfullscreen.sh”:

#!/bin/sh

#####################################################
#
# TITLE must be the text of the titlebar the application will have
#

TITLE="untitled"
APP="adie"


### run it
$APP &

### give it time to create its window
sleep 2;


### try to find out its windowID
ABC=`xwininfo -name $TITLE|sed "s/^.*id://"|sed "s/.\".*//"|sed "s/ [^0-9].*$//"`

echo $ABC

### set it to fullscreen-mode
./win_fullscreen $ABC


#######################################################
# uncomment for tests: finish fullscreen after 10 seconds

#sleep 10;
#./win_fullscreen $ABC

Make it executable:
chmod 755 runfullscreen.sh

In this script, you must change these 2 lines to your needs:
TITLE=“untitled”
APP=“adie”

APP is the command to run your application.
TITLE is the text the Windowtitle of your application has right after it started.

Now run it:
./runfullscreen.sh

The way I find out the windowID (via xwininfo) might not be very elegant.
Any enhancements are appreciated.

Mark

If you have wmctrl installed, you can type

wmctrl -i -r <windowId> -b add,fullscreen,above

to fullscreenize a window (above if for StaysOnTop)

In fvwm, you can do is with a function

[code]DestroyFunc Fullscreen
AddToFunc Fullscreen

  • I WindowStyle !Borders NoTitle
  • I Layer 0 10
  • I Schedule 0 Maximize ewmhiwa 100 100[/code]

Here I also remove the borders. The Schedule 0 is necessary, or fvwm use the window size borders included to maximize it.

It seems to me like the function is the simplest solution :wink:

Hm, but how can you get the windowID , when you start a process from a shellscript?

I think it is not clean to fetch it via xwininfo using the name of the window.

I’d prefer something like this:
$pid = exec “myprog”
$winID = ps -a | grep $pid | sed “…filter out the windowid from this line…”

But in the processlist, you do not find the windowid.

Mark

One “overkill” solution I found to get Window Id from the shell: Preload xlib to wrap calls to XCreateWindow and XCreateSimpleWindow.

Here is the code

[code]// gcc -Wall xwrapper.c -shared -ldl -o libx.so

#include <stdio.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#define __USE_GNU
#include <dlfcn.h>

typedef Window (*fsptr)(Display *display, Window parent, int x, int y, unsigned
int width, unsigned int height, unsigned int border_width, unsigned long border
, unsigned long background);

typedef Window (*fptr)(Display *display, Window parent, int x, int y, unsigned int
width, unsigned int height, unsigned int border_width, int depth, unsigned int
class, Visual *visual, unsigned long valuemask, XSetWindowAttributes
*attributes);

static fptr f=0;
static fsptr fs=0;

void attribute ((constructor)) my_init(void){
f=(fptr)dlsym(RTLD_NEXT,“XCreateWindow”);
fs=(fsptr)dlsym(RTLD_NEXT,“XCreateSimpleWindow”);

}

Window XCreateWindow(Display *display, Window parent, int x, int y, unsigned int
width, unsigned int height, unsigned int border_width, int depth, unsigned int
class, Visual *visual, unsigned long valuemask, XSetWindowAttributes
*attributes){
Window w= f(display,parent,x,y,width,height,border_width,depth,class,visual,valuemask,attributes);
printf(“W: %x\n”,w);
return w;
}
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)
{
Window w=
fs(display,parent,x,y,width,height,border_width,border, background);
printf(“SW: %x\n”,w);
return w;
}[/code]

Once compile, you get libx.so.

To preload it, you need yo put it is LD_PRELOAD environment variable. For instance

LD_PRELOAD=/path/to/libx.so emacs

(as each widget is a window, only the first window id should be used)

The problem is that for setuid/gid programs (like xterm, and many terminal emulators), it won’t be loaded, unless it is in one of the standard library directory and with a setgid bit (chmod g+s libx.so) (according to man ld-linux.so; did not try on BSD).

This feature does not work on my computer (bug?)… However, if I put /path/to/libx.so in /etc/ld.so.preload, it works, but for all programs, even if we don’t want window id. The best workaround I found is to remove setgid bit on xterm, as I really don’t care about wtmp entries.

Please tell me if it works on your system.

big thx till now, i will test it at the weekend…

zonk, your program itself works fine on my system (Linux Mandrake 9.2).

I run it in a folder:
/usr/local/wxb-desktop01/resource/test/expose2.2/resource

like this:
LD_PRELOAD=pwd/libx.so rxvt

Works as root and user, with rxvt, xterm and adie.

But somehow I am too stupid, to pipe the output to a variable I can use to run
./win_fullscreen $WINID

:blush: :unamused:

I will test it later, maybe I am just too tired (did not sleep tonight) :wink:

Thanks alot, this approach is completely new to me, and looks very interesting :slight_smile:

I have to same shell problem. Typing

a=$(LD_PRELOAD=... rxvt | head -1 | awk '{ print $2 }')

never returns… I’m affraid one will have to write C code, which popen rxvt, read the first line, and raise it…

I’d have been more absolute with that, myself:

+ I ThisWindow WindowStyle !Title, !Borders

Note the commas – this is now the preferred way to separate out multiple style line attributes.

You must get into the habit, when you have a style line like this in a function that you add:

+ I UpdateStyles

… as the last line in the function, otherwise you’ll find some odd things can happen. Note that “UpdateStyles” works in 2.5.12 onwards, for me at least. In the older FVWM releases “RecaptureWindow” used to be used, but it’s deprecated now.

– Thomas Adam

I have no title and hence NoTitle is not in my config, then I added it without testing… shame on me :oops:

Works much better! thanks.

not workin here :frowning:

he shows me always in normal window.

Can you be more specific?

– Thomas Adam

i have a script file over a button i’m strating tarantella client :

http://www.tarantella.com/download/clients/download.php/http/Tarantella.E3/3.40.911/native/tnci3li.tar

the title is “XX2 FS - Secure Global Desktop” maybe it helps.

and this programm starts in normal window mode (1024x768) but not in FullScreen !

Well, the link you gave me timed out for me. Are you saying that the function above doesn’t work for you, or that the specific application is causing problems?

– Thomas Adam.

the fuction not work for me

I wrote a program in wxbasic, that does it.

Download this file and extract:
noforum.de/files/runfullscreen/runfullscreen.tgz

Now cd to the new folder:
cd runfullscreen

Now run the script here:
./run.sh xterm

xterm will start, and after one second switch to fullscreen-mode.

If wxbasic does not run on your system:
cd to /wxbasic22i-x
./_compileconsole.sh

Now you get a “fresh” file “wxbasic”.
Copy it to the folder /resource

How it works:
First, the wxbasic-program (main.wxb) lists all visible windows.
Then it starts xterm
then it lists all windows again, and compares them to the old list.
If there is a new window in the list, it must be our xterm - and it will be set to fullscreen using my extension I described there: viewtopic.php?t=213

The last step will be repeated up to 10 times with a 1-second-delay, as it varies how long a program needs to create a window.

xterm is very fast, openoffice will be very slow.

The only problem that can appear is, when there also starts another program at the same time.
then my script can not know, which window is the one it created.

Greets, Mark