Pular para o conteúdo

Proteção de tela ou vídeo como papel de parede

Nesse tutorial vou explicar a maneira fácil e rápida de colocar um vídeo no papel de parede.
M4iir1c10 M4iir1c10
Hits: 69.189 Categoria: Linux Subcategoria: Gráficos/Imagens
  • Indicar
  • Impressora
  • Denunciar
O Viva o Linux depende da receita de anúncios para se manter. Ative os cookies aqui para nos patrocinar.
Não conseguimos carregar os anúncios. Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.

Parte 2: Código-fonte

Esse é o código fonte do xwinwrap, copie e salve como "xwinwrap.c", logo abaixo nessa mesma página tem o Makefile, salve-o como Makefile e use o comando de compilação...

/* Copie dessa linha abaixo
*
* Copyright © 2005 Novell, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of
* Novell, Inc. not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior permission.
* Novell, Inc. makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*
* NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: David Reveman <davidr@novell.com>
*/

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

#include <X11/extensions/shape.h>
#include <X11/extensions/Xrender.h>

#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/types.h>

#define WIDTH  512
#define HEIGHT 384

#define OPAQUE 0xffffffff

#define NAME "xwinwrap"

static pid_t pid = 0;

static char **childArgv = 0;
static int  nChildArgv  = 0;

static int
addArguments (char **argv, int  n)
{
    char **newArgv;
    int  i;

    newArgv = realloc (childArgv, sizeof (char *) * (nChildArgv + n));
    if (!newArgv)
   return 0;

    for (i = 0; i < n; i++)
   newArgv[nChildArgv + i] = argv[i];

    childArgv   = newArgv;
    nChildArgv += n;

    return n;
}

static void
setWindowOpacity (Display      *dpy,
        Window       win,
        unsigned int opacity)
{
    CARD32 o;

    o = opacity;

    XChangeProperty (dpy, win, XInternAtom (dpy, "_NET_WM_WINDOW_OPACITY", 0),
           XA_CARDINAL, 32, PropModeReplace,
           (unsigned char *) &o, 1);
}

static Visual *
findArgbVisual (Display *dpy, int scr)
{
    XVisualInfo      *xvi;
    XVisualInfo      template;
    int         nvi;
    int         i;
    XRenderPictFormat   *format;
    Visual      *visual;

    template.screen = scr;
    template.depth  = 32;
    template.class  = TrueColor;

    xvi = XGetVisualInfo (dpy,
           VisualScreenMask |
           VisualDepthMask  |
           VisualClassMask,
           &template,
           &nvi);
    if (!xvi)
   return 0;

    visual = 0;
    for (i = 0; i < nvi; i++)
    {
   format = XRenderFindVisualFormat (dpy, xvi[i].visual);
   if (format->type == PictTypeDirect && format->direct.alphaMask)
   {
       visual = xvi[i].visual;
       break;
   }
    }

    XFree (xvi);

    return visual;
}

static void
sigHandler (int sig)
{
    kill (pid, sig);
}

static void
usage (void)
{
    fprintf (stderr, "Usage: %s [-g] [-ni] [-argb] [-fs] [-s] [-st] [-sp] [-a] "
        "[-b] [-nf]        [-o OPACITY] -- COMMAND ARG1... ", NAME);
}

int
main (int argc, char **argv)
{
    Display    *dpy;
    Window    win;
    Window    root;
    int       screen;
    XSizeHints    xsh;
    XWMHints    xwmh;
    char    widArg[256];
    char    *widArgv[] = { widArg };
    char    *endArg = NULL;
    int       i;
    int       status = 0;
    unsigned int opacity = OPAQUE;
    int       x = 0;
    int       y = 0;
    unsigned int width = WIDTH;
    unsigned int height = HEIGHT;
    int       argb = 0;
    int       fullscreen = 0;
    int       noInput = 0;
    int       noFocus = 0;
    Atom    state[256];
    int       nState = 0;

    dpy = XOpenDisplay (NULL);
    if (!dpy)
    {
   fprintf (stderr, "%s: Error: couldn't open display ", argv[0]);
   return 1;
    }

    screen = DefaultScreen (dpy);
    root   = RootWindow (dpy, screen);

    for (i = 1; i < argc; i++)
    {
   if (strcmp (argv[i], "-g") == 0)
   {
       if (++i < argc)
      XParseGeometry (argv[i], &x, &y, &width, &height);
   }
   else if (strcmp (argv[i], "-ni") == 0)
   {
       noInput = 1;
   }
   else if (strcmp (argv[i], "-argb") == 0)
   {
       argb = 1;
   }
   else if (strcmp (argv[i], "-fs") == 0)
   {
       state[nState++] = XInternAtom (dpy, "_NET_WM_STATE_FULLSCREEN", 0);
       fullscreen = 1;
   }
   else if (strcmp (argv[i], "-s") == 0)
   {
       state[nState++] = XInternAtom (dpy, "_NET_WM_STATE_STICKY", 0);
   }
   else if (strcmp (argv[i], "-st") == 0)
   {
       state[nState++] = XInternAtom (dpy, "_NET_WM_STATE_SKIP_TASKBAR", 0);
   }
   else if (strcmp (argv[i], "-sp") == 0)
   {
       state[nState++] = XInternAtom (dpy, "_NET_WM_STATE_SKIP_PAGER", 0);
   }
   else if (strcmp (argv[i], "-a") == 0)
   {
       state[nState++] = XInternAtom (dpy, "_NET_WM_STATE_ABOVE", 0);
   }
   else if (strcmp (argv[i], "-b") == 0)
   {
       state[nState++] = XInternAtom (dpy, "_NET_WM_STATE_BELOW", 0);
   }
   else if (strcmp (argv[i], "-nf") == 0)
   {
       noFocus = 1;
   }
   else if (strcmp (argv[i], "-o") == 0)
   {
       if (++i < argc)
      opacity = (unsigned int) (atof (argv[i]) * OPAQUE);
   }
   else if (strcmp (argv[i], "--") == 0)
   {
       break;
   }
   else
   {
       usage ();

       return 1;
   }
    }

    for (i = i + 1; i < argc; i++)
    {
   if (strcmp (argv[i], "WID") == 0)
       addArguments (widArgv, 1);
   else
       addArguments (&argv[i], 1);
    }

    if (!nChildArgv)
    {
   fprintf (stderr, "%s: Error: couldn't create command line ", argv[0]);
   usage ();

   return 1;
    }

    addArguments (&endArg, 1);

    if (fullscreen)
    {
   xsh.flags  = PSize | PPosition;
   xsh.width  = DisplayWidth (dpy, screen);
   xsh.height = DisplayHeight (dpy, screen);
    }
    else
    {
   xsh.flags  = PSize;
   xsh.width  = width;
   xsh.height = height;
    }

    xwmh.flags = InputHint;
    xwmh.input = !noFocus;

    if (argb)
    {
   XSetWindowAttributes attr;
   Visual           *visual;

   visual = findArgbVisual (dpy, screen);
   if (!visual)
   {
       fprintf (stderr, "%s: Error: couldn't find argb visual ", argv[0]);
       return 1;
   }

   attr.background_pixel = 0;
   attr.border_pixel     = 0;
   attr.colormap         = XCreateColormap (dpy, root, visual, AllocNone);

   win = XCreateWindow (dpy, root, 0, 0, xsh.width, xsh.height, 0,
              32, InputOutput, visual,
              CWBackPixel | CWBorderPixel | CWColormap, &attr);
    }
    else
    {
   win = XCreateWindow (dpy, root, 0, 0, xsh.width, xsh.height, 0,
              CopyFromParent, InputOutput, CopyFromParent,
              0, NULL);
    }

    XSetWMProperties (dpy, win, NULL, NULL, argv, argc, &xsh, &xwmh, NULL);

    if (opacity != OPAQUE)
   setWindowOpacity (dpy, win, opacity);

    if (noInput)
    {
   Region region;

   region = XCreateRegion ();
   if (region)
   {
       XShapeCombineRegion (dpy, win, ShapeInput, 0, 0, region, ShapeSet);
       XDestroyRegion (region);
   }
    }

    if (nState)
   XChangeProperty (dpy, win, XInternAtom (dpy, "_NET_WM_STATE", 0),
          XA_ATOM, 32, PropModeReplace,
          (unsigned char *) state, nState);

    XMapWindow (dpy, win);

    XSync (dpy, win);

    sprintf (widArg, "0x%x", (int) win);

    pid = fork ();

    switch (pid) {
    case -1:
   perror ("fork");
   return 1;
    case 0:
   execvp (childArgv[0], childArgv);
   perror (childArgv[0]);
   exit (2);
   break;
    default:
   break;
    }

    signal (SIGTERM, sigHandler);
    signal (SIGINT,  sigHandler);

    for (;;)
    {
   if (waitpid (pid, &status, 0) != -1)
   {
       if (WIFEXITED (status))
      fprintf (stderr, "%s died, exit status %d ", childArgv[0],
          WEXITSTATUS (status));

       break;
   }
    }

    XDestroyWindow (dpy, win);
    XCloseDisplay (dpy);

    return 0;
}
O Viva o Linux depende da receita de anúncios para se manter. Ative os cookies aqui para nos patrocinar.
Não conseguimos carregar os anúncios. Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.

Bom, depois de copiar o código vamos ao arquivo "Makefile", que será chamado na hora da compilação.

Início do Makefile, copie da próxima linha abaixo e salve como Makefile:

CFLAGS+=-g -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls
LDFLAGS+=-lX11 -lXext -lXrender

PROGS=xwinwrap

xwinwrap: xwinwrap.o

all: $(PROGS)

clean:
   rm -f $(PROGS) *.o

Depois dos dois arquivos prontos entra em cena a dupla:

$ make & make install

O Viva o Linux depende da receita de anúncios para se manter. Ative os cookies aqui para nos patrocinar.
Não conseguimos carregar os anúncios. Se usa bloqueador, considere liberar o Viva o Linux para nos patrocinar.
   1. Introdução
   2. Código-fonte
   3. Rodando

Rode Linux no seu iPod

Como controlar todas as mídias da sua casa somente com 1 controle remoto e 1 Linux

Criando vídeo com características de DVD

Aprendendo a melhorar os seus scripts

MEncoder - Criando Programa Gráfico Para Conversão

Programação visual (módulo 1)

Aceleração 3D Nvidia no Debian Etch

Um método para a construção da interface gráfica MATE no Slackware

Imagination: Transforme suas fotos em DVD

Gnome Shell e Extensions no Ubuntu 11.10

#1 Comentário enviado por marceloatie em 13/11/2007 - 09:00h
Ubuntu@Gutsy:~$ sudo apt-get install xwinwrap
Lendo lista de pacotes... Pronto
Construindo árvore de dependências
Reading state information... Pronto
E: Impossível achar pacote xwinwrap
#3 Comentário enviado por cruzeirense em 13/11/2007 - 11:41h
É interessante, apesar de inútil. Tenho um programa que faz algo semelhante no xp, pvr plus que coloca a imagem capturada de tv como papel de parede, bem bacana...
#4 Comentário enviado por fdavid em 13/11/2007 - 16:29h
xine -R faz o mesmo !
#5 Comentário enviado por M4iir1c10 em 13/11/2007 - 20:56h
E a protecao de tela? da pra fazer com o xine -R, pvr ou mesmo o Mplayer ?

Desculpem uma falha no final do artigo onde eu coloquei o codigo-fonte o comando para compilar e :

Make
sudo cp xwinwrap.o /usr/lib
sudo cp xwinwrap /usr/bin

o Make install vai retornar erro... foi mal... hehehe!
#6 Comentário enviado por renato_pacheco em 16/11/2007 - 11:20h
Kra, pq q o meu comando make dá esse problema?

renato@renato:~/Desktop/xwinwrap$ make
Makefile:11: *** missing separator. Stop.

Tá faltando alguma coisa, mas num sei o q é.
#8 Comentário enviado por renato_pacheco em 18/11/2007 - 14:47h
Esqueci d t falar, mas eu havia conseguido. Tinha alguns espaços a mais dentro do Makefile e eu os tirei. Agora há outro problema: quando eu o executo, funciona normalmente, mas os meus ícones da área d trabalho não aparecem. Como faço pra aparecerem?

Valews!
#9 Comentário enviado por removido em 19/11/2007 - 15:18h
brother, instalei, mandei rodar
e simplesmente nao aconteceu nada......rs
oq será que houve???

quando mando rodar o matrix por exemplo, ele diz que o arquivo nao foi encontrado, mas eu tenho o glmatrix la
#10 Comentário enviado por renato_pacheco em 19/11/2007 - 15:30h
homemdegelo,

Eu passei por isso tb. É q o caminho dos screen savers depende d cada distro. Para vc tirar essa dúvida, execute o comando:

# find / -iname glmatrix

Eu encontrei o meu dessa forma. Falows!
#11 Comentário enviado por removido em 19/11/2007 - 15:41h
blz renato, vou testar
se der problema voltou a ti enxer....hehehe

valeu,

abraço
#12 Comentário enviado por removido em 20/11/2007 - 21:57h
entao velho, testei e nada
o meu caminho é o mesmo descrito pelo mauricio, mas mesmo assim da esse erro:

root@leo-desktop:/home/leo# xwinwrap -ni -argb -fs -s -st -sp -a -nf -- /usr/lib/misc/xscreensaver/glmatrix -root -window-id WID &
[1] 5999
root@leo-desktop:/home/leo# /usr/lib/misc/xscreensaver/glmatrix: No such file or directory
/usr/lib/misc/xscreensaver/glmatrix died, exit status 2


alguem sabe oq é??
#13 Comentário enviado por SuporteTecnicoID em 06/01/2008 - 19:06h
Procure com o :

whereis xscreensaver

Vai mostrar os caminhos do xscreensaver se existir, caso não exista, vc não pode esquecer de ter o xscreensaver instalado.

#14 Comentário enviado por rayfcrols em 23/04/2008 - 17:42h
Mauricio, ou que puder ajudar, eu conseguir que rodasse no Ubuntu 8.04 mais somente tomando toda tela(digo, funcionando +- como um screen) não teria ou não era para funcionar como como um papel de parede animado???
#15 Comentário enviado por kirabouts em 04/05/2009 - 05:06h
TTo tentando usar essa dica no meu ubuntu 9.04, mas nao rola.. instalei o xscreensaver pelo pacote que baixei da net.. fiz tudo exatamente como no tuto e depois de executar o comando no terminal para exercutar o screensaver.. a tela toda fica coberta pelo escreen saver.. ou seja. nao há como mexer no desktop.. fica tdo piscando... se alguem tiver uma solução me deixa uma msn ou manda um email pra joao__silveira@hotmail.com..
abraço!!!
#16 Comentário enviado por bruc3 em 13/10/2009 - 17:58h
[root @ Slackware protecaodetela]# ls
Makefile xwinwrap.c
[root @ Slackware protecaodetela]# make
Makefile:11: *** faltando o separador. Pare.
[root @ Slackware protecaodetela]#


PORQUE?
#17 Comentário enviado por bruc3 em 13/10/2009 - 17:58h
MSN: raaafid@hotmail.com

Quem puder me ajudar, por favor. vaLeu! x)

Contribuir com comentário

Entre na sua conta para comentar.