IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaFX Discussion :

Docker une fenêtre en JAVA avec JNA.


Sujet :

JavaFX

  1. #1
    Futur Membre du Club
    Homme Profil pro
    chocolatier
    Inscrit en
    Janvier 2015
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : chocolatier

    Informations forums :
    Inscription : Janvier 2015
    Messages : 5
    Points : 7
    Points
    7
    Par défaut Docker une fenêtre en JAVA avec JNA.
    Bonjour a tous.
    J'essaie de traduire ce code C en Java avec JNA.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    if(dock) {
            type = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
            XChangeProperty(
                            dpy,
                            w,
                            XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False),
                            XInternAtom(dpy, "ATOM", False),
                            32,
                            PropModeReplace,
                            (unsigned char *)&type,
                            1
                            );
     
            type = XInternAtom(dpy, "_NET_WM_STATE_ABOVE", False);
            XChangeProperty(
                            dpy,
                            w,
                            XInternAtom(dpy, "_NET_WM_STATE", False),
                            XInternAtom(dpy, "ATOM", False),
                            32,
                            PropModeReplace,
                            (unsigned char *)&type,
                            1
                            );
     
            type = XInternAtom(dpy, "_NET_WM_STATE_STICKY", False);
            XChangeProperty(
                            dpy,
                            w,
                            XInternAtom(dpy, "_NET_WM_STATE", False),
                            XInternAtom(dpy, "ATOM", False),
                            32,
                            PropModeAppend,
                            (unsigned char *)&type,
                            1
                            );
     
     
            desktop = 0xffffffff;
            XChangeProperty(
                            dpy,
                            w,
                            XInternAtom(dpy, "_NET_WM_DESKTOP", False),
                            XInternAtom(dpy, "CARDINAL", False),
                            32,
                            PropModeReplace,
                            (unsigned char *)&desktop,
                            1
                            );
    }
    En Java pour fixer une fenetre en type dock par exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    X11.Atom atomType = getAtom("_NET_WM_WINDOW_TYPE_DOCK");
    x11.XChangeProperty(x11Display,     // DISPLAY
                                     win,               // FENETRE
                                     getAtom("_NET_WM_WINDOW_TYPE"),
                                     getAtom("ATOM"),
                                     32,
                                     X11.PropModeReplace,
                                     atomType, // <--
                                     1);
    J'arrive a recuperer une valeur de type X11.Atom avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    X11.AtomByReference xa_ret_type_ref = new X11.AtomByReference();
    ...
    X11.Atom xa_ret_type = xa_ret_type_ref.getValue();
    Mon probleme se situe au niveau de 'atomType' puisqu'il faut passer
    la reference de ce type. L'erreur renvoye est logique :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    'incompatible types: Atom cannot be converted to Pointer'
    J'ai essaye de passer par le type 'Pointer' de JNA mais sans succes.
    J'ai cherche et trouve des exemples de code pour passer la reference
    avec JNA, mais rien qui puisse m'aider.
    Si quelqu'un a une idee ou une piste
    Merci par avance.

  2. #2
    Futur Membre du Club
    Homme Profil pro
    chocolatier
    Inscrit en
    Janvier 2015
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : chocolatier

    Informations forums :
    Inscription : Janvier 2015
    Messages : 5
    Points : 7
    Points
    7
    Par défaut
    Salut.
    Je suis sous mint XFCE et NetBean.
    Bon j'ai reussi a passer la reference du type Atom avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
            X11.Atom atomType = getAtom("_NET_WM_WINDOW_TYPE_DOCK");
            NativeLongByReference longByRef = new NativeLongByReference();
            longByRef.setValue(atomType);
     
            x11.XChangeProperty(    x11Display,
                                    win,
                                    getAtom("_NET_WM_WINDOW_TYPE"),
                                    X11.XA_ATOM, // <-- changement
                                    32,
                                    X11.PropModeReplace,
                                    longByRef.getPointer(), // <-- 
                                    1);
     
            x11.XFlush(x11Display);
    La fenetre se docke bien, la commande " wmctrl -l " affiche
    un numero de bureau de -1 au meme titre que les composants XFCE.
    Elle n''apparait plus dans la barre des taches, elle s'affiche
    dans tous les bureaux. Par contre elle se positionne au dessus
    des autres fenetres.
    J'affiche le code exemple des que possible, pour ceux que ca interesse.

  3. #3
    Futur Membre du Club
    Homme Profil pro
    chocolatier
    Inscrit en
    Janvier 2015
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : chocolatier

    Informations forums :
    Inscription : Janvier 2015
    Messages : 5
    Points : 7
    Points
    7
    Par défaut
    Bon, le code pour docker une fenetre avec JavaFX et JNA
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
     
    package javax11test;
     
    import com.sun.jna.Native;
    import com.sun.jna.NativeLong;
    import com.sun.jna.Pointer;
    import com.sun.jna.platform.unix.X11;
    import com.sun.jna.ptr.IntByReference;
    import com.sun.jna.ptr.NativeLongByReference;
    import com.sun.jna.ptr.PointerByReference;
    import java.util.HashMap;
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
     
    public class JavaX11Test extends Application {
     
        private static final int _NET_WM_STATE_REMOVE = 0;
        private static final int _NET_WM_STATE_ADD    = 1;
        private static final int _NET_WM_STATE_TOGGLE = 2;
     
        private X11 x11;    
        private X11.Display x11Display;
        private X11.Window x11Window;
     
        public static void main(String[] args) {
            launch(args);
        }
     
        @Override
        public void start(Stage primaryStage) {
     
            // ==== Init X11
     
            x11 = X11.INSTANCE;
     
            x11Display = x11.XOpenDisplay(null);
            if (x11Display == null)
                throw new Error("Can't open X Display");
     
            x11Window = x11.XDefaultRootWindow(x11Display);
            if (x11Window == null)
                throw new Error("Can't open default root window");
     
            // ==== Creation de la fenetre
     
            Label lab = new Label();
            lab.setText("Hello World");
     
            StackPane root = new StackPane();
            root.getChildren().add(lab);
     
            Scene scene = new Scene(root, 200, 200);
     
            // Enlever les bordures de la fenetre
            primaryStage.initStyle(StageStyle.TRANSPARENT);
     
            primaryStage.setTitle("HelloWorld");
            primaryStage.setScene(scene);
            primaryStage.show();
     
            // ==== Docker la fenetre
     
            // On recupere la fenetre
            X11.Window wind = getWindowProperty(X11.XA_WINDOW, getAtom("_NET_ACTIVE_WINDOW"));
     
            // On la transforme en type dock
            // et on la glisse dessous les autres
            windowDock(wind);
            windowBelow(wind);
        }
     
        // Docker une fentre
        public void windowDock(X11.Window win) {
     
            X11.Atom atomType = getAtom("_NET_WM_WINDOW_TYPE_DOCK");
            NativeLongByReference longByRef = new NativeLongByReference();
            longByRef.setValue(atomType);
            x11.XChangeProperty(    x11Display,
                                    win,
                                    getAtom("_NET_WM_WINDOW_TYPE"),
                                    X11.XA_ATOM,
                                    32,
                                    X11.PropModeReplace,
                                    longByRef.getPointer(),
                                    1);
            x11.XFlush(x11Display);
        }
     
        // Glisser une fenetre au dessous de toutes les autres
        public int windowBelow(X11.Window win) {
            X11.XClientMessageEvent event;
            int maskVal = X11.SubstructureRedirectMask | X11.SubstructureNotifyMask;
            NativeLong mask = new NativeLong(maskVal);
            event = new X11.XClientMessageEvent();
            event.type = X11.ClientMessage;
            event.serial = new NativeLong(0);
            event.send_event = 1;
            event.message_type = getAtom("_NET_WM_STATE");
            event.window = win;
            event.format = 32;
            event.data.setType(NativeLong[].class);
            event.data.l[0] = new NativeLong(_NET_WM_STATE_ADD);
            event.data.l[1] = getAtom("_NET_WM_STATE_BELOW");
            event.data.l[2] = new NativeLong(0);
            event.data.l[3] = new NativeLong(0);
            event.data.l[4] = new NativeLong(0);
            X11.XEvent e = new X11.XEvent();
            e.setTypedValue(event);
            if (x11.XSendEvent(x11Display, x11Window, 0, mask, e) != 0) {
                x11.XFlush(x11Display);
                return X11.Success;
            }
            else throw new Error("Cannot send " + "_NET_WM_STATE_BELOW" + " event.");
        }
     
        public X11.Atom getAtom(String name) {
            HashMap<String, X11.Atom> atomsHash = new HashMap<>();
            X11.Atom atom = atomsHash.get(name);
            if (atom == null) {
                atom = x11.XInternAtom(x11Display, name, false);
                atomsHash.put(name, atom);
            }
            return atom;
        }        
     
        public X11.Window getWindowProperty(X11.Atom xa_prop_type, X11.Atom xa_prop_name) {
            byte[] property = getProperty(xa_prop_type, xa_prop_name);
            // Bytes to int
            Integer windowId;
            windowId =  ((property[3] & 0xff) << 24)
                    | ((property[2] & 0xff) << 16)
                    | ((property[1] & 0xff) << 8)
                    | ((property[0] & 0xff));
            X11.Window x11Win = new X11.Window(windowId);
            return (x11Win);
        }
     
        public byte[] getProperty(X11.Atom xa_prop_type, X11.Atom xa_prop_name) {
            X11.AtomByReference xa_ret_type_ref = new X11.AtomByReference();
            IntByReference ret_format_ref = new IntByReference();
            NativeLongByReference ret_nitems_ref = new NativeLongByReference();
            NativeLongByReference ret_bytes_after_ref = new NativeLongByReference();
            PointerByReference ret_prop_ref = new PointerByReference();
            NativeLong long_offset = new NativeLong(0);
            NativeLong long_length = new NativeLong(4096 / 4);
            if (x11.XGetWindowProperty(x11Display, x11Window, xa_prop_name, long_offset, long_length, false,
                xa_prop_type, xa_ret_type_ref, ret_format_ref,
                ret_nitems_ref, ret_bytes_after_ref, ret_prop_ref) != X11.Success) {
                String prop_name = x11.XGetAtomName(x11Display, xa_prop_name);
                throw new Error("Cannot get " + prop_name + " property.");
            }
            X11.Atom xa_ret_type = xa_ret_type_ref.getValue();
            Pointer ret_prop = ret_prop_ref.getValue();
            if (xa_ret_type == null || xa_prop_type == null ||
                !xa_ret_type.toNative().equals(xa_prop_type.toNative())) {
                x11.XFree(ret_prop);
                String prop_name = x11.XGetAtomName(x11Display, xa_prop_name);
                throw new Error("Invalid type of " + prop_name + " property");
            }
            int ret_format = ret_format_ref.getValue();
            long ret_nitems = ret_nitems_ref.getValue().longValue();
            int nbytes;
            switch (ret_format) {
                case 32:
                    nbytes = Native.LONG_SIZE;
                    break;
                case 16:
                    nbytes = Native.LONG_SIZE / 2;
                    break;
                case 8:
                    nbytes = 1;
                    break;
                case 0:
                    nbytes = 0;
                    break;
                default:
                    throw new Error("Invalid return format");
            }
            int length = Math.min((int) ret_nitems * nbytes, 4096);
            byte[] ret = ret_prop.getByteArray(0, length);
            x11.XFree(ret_prop);
            return ret;
        }
    }
    Il y a aussi une fonction pour placer la fenetre au dessous des autres.
    Je me suis tres largement inspire d'une API fournie avec
    la librairie JNA qu'on peut trouver dans le dossier jna-master/
    ici -> jna-master/contrib/x11/src/jnacontrib/x11/api/

  4. #4
    Futur Membre du Club
    Homme Profil pro
    chocolatier
    Inscrit en
    Janvier 2015
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations professionnelles :
    Activité : chocolatier

    Informations forums :
    Inscription : Janvier 2015
    Messages : 5
    Points : 7
    Points
    7
    Par défaut
    Salut.
    A l'execution du code de temps a temps, c'est l'editeur
    NetBean qui se docke . Pourtant je recupere l'ID de
    la fenetre active juste apres l'affichage de la scene
    Je suis alle un peu plus loin pour recuperer l'ID de la
    fenetre docker. Le message 'hello world' ca va un moment,
    alors j'ai affiche une horloge
    Je marque comme resolu.
    Le code example pour Docker une fenetre avec JNA :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
     
    /*****************************************************************
     * JAVAX11TEST
     *****************************************************************/
    package javax11test;
     
     
     
    /*****************************************************************
     * IMPORTS
     *****************************************************************/
    import com.sun.jna.NativeLong;
    import com.sun.jna.Pointer;
    import com.sun.jna.platform.unix.X11;
    import com.sun.jna.ptr.IntByReference;
    import com.sun.jna.ptr.NativeLongByReference;
    import com.sun.jna.ptr.PointerByReference;
     
    import java.io.UnsupportedEncodingException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
     
    import java.util.Calendar;
    import java.util.HashMap;
    import java.util.Map;
     
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.stage.Stage;
    import javafx.scene.control.Label;
    import javafx.scene.layout.StackPane;
    import javafx.stage.StageStyle;
    import javafx.util.Duration;
     
    import javafx.animation.Animation;
    import javafx.animation.KeyFrame;
    import javafx.animation.Timeline;
     
    import javafx.event.ActionEvent;
     
     
     
    /*****************************************************************
     * CLASS JavaX11Test
     *****************************************************************/
    public class JavaX11Test extends Application {
     
        private static final int _NET_WM_STATE_ADD = 1;
     
        private static X11.Atom ATOM_NET_WM_WINDOW_TYPE;
        private static X11.Atom ATOM_NET_WM_WINDOW_TYPE_DOCK;
        private static X11.Atom ATOM_NET_WM_STATE;
        private static X11.Atom ATOM_NET_WM_STATE_BELOW;
        private static X11.Atom ATOM_NET_CLIENT_LIST;
     
        private final X11           x11;    
        private final X11.Display   x11Display;
        private final X11.Window    x11RootWindow;
     
        private Label label;
     
     
     
        /*****************************************************************
         * MAIN
         * @param args
         *****************************************************************/
        public static void main(String[] args) {
     
            launch(args);
     
        }
     
     
     
        /*****************************************************************
         * CONSTRUCTEUR
         *****************************************************************/
        public JavaX11Test () {
     
            x11 = X11.INSTANCE;
     
            x11Display = x11.XOpenDisplay(null);
            if (x11Display == null)
                throw new Error("Can't open X Display");
     
            x11RootWindow = x11.XDefaultRootWindow(x11Display);
            if (x11RootWindow == null)
                throw new Error("Can't open default root window");
     
            ATOM_NET_WM_WINDOW_TYPE         = x11.XInternAtom(x11Display, "_NET_WM_WINDOW_TYPE", false);
            ATOM_NET_WM_WINDOW_TYPE_DOCK    = x11.XInternAtom(x11Display, "_NET_WM_WINDOW_TYPE_DOCK", false);
            ATOM_NET_WM_STATE               = x11.XInternAtom(x11Display, "_NET_WM_STATE", false);
            ATOM_NET_WM_STATE_BELOW         = x11.XInternAtom(x11Display, "_NET_WM_STATE_BELOW", false);
            ATOM_NET_CLIENT_LIST            = x11.XInternAtom(x11Display, "_NET_CLIENT_LIST", false);
     
        }
     
     
     
        /*****************************************************************
         * START
         *****************************************************************/
        @Override
        public void start(Stage primaryStage) {
     
            label = new Label();
            label.setStyle( "-fx-font-smoothing-type: lcd;" + 
                            "-fx-text-fill: black;" +
                            "-fx-font-weight: bold;" +
                            "-fx-font-size: 16;");
     
            StackPane root = new StackPane();
            root.getChildren().add(label);
     
            Scene scene = new Scene(root, 100, 50);
     
            primaryStage.initStyle(StageStyle.UNDECORATED);
     
            primaryStage.setTitle("HelloWorld");
            primaryStage.setX(10);
            primaryStage.setY(200);
            primaryStage.setScene(scene);
     
            MakeClock();
     
            primaryStage.show();
     
            String className = getClass().getName();
     
            int[]   windowsIDList;
            int     windowID;
     
            windowsIDList   = getWindowsIDList();
            windowID        = findWindowIDClass(windowsIDList, className);
     
            X11.Window wind = new X11.Window(windowID);
     
            windowDock(wind);
            windowBelow(wind);
     
        }
     
     
     
        /*****************************************************************
         * MAKECLOCK
         *****************************************************************/
        public void MakeClock() {
     
            Timeline digitalTime = new Timeline(
     
                new KeyFrame(Duration.seconds(0), (ActionEvent actionEvent) -> {
     
                    DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
                    Calendar cal = Calendar.getInstance();
     
                    label.setText(dateFormat.format(cal.getTime()));
     
                    }),
                    new KeyFrame(Duration.seconds(1))
     
            );
     
            digitalTime.setCycleCount(Animation.INDEFINITE);
            digitalTime.play();
     
        }
     
     
     
        /*****************************************************************
         * WINDOWDOCK
         * @param win
         *****************************************************************/
        public void windowDock(X11.Window win) {
     
            X11.Atom atomType = ATOM_NET_WM_WINDOW_TYPE_DOCK;
            NativeLongByReference longByRef = new NativeLongByReference();
            longByRef.setValue(atomType);
     
            x11.XChangeProperty(    x11Display,
                                    win,
                                    ATOM_NET_WM_WINDOW_TYPE,
                                    X11.XA_ATOM,
                                    32,
                                    X11.PropModeReplace,
                                    longByRef.getPointer(),
                                    1);
            x11.XFlush(x11Display);
     
        }
     
     
     
        /*****************************************************************
         * WINDOWBELOW
         * @param win
         * @return 
         *****************************************************************/
        public int windowBelow(X11.Window win) {
     
            X11.XClientMessageEvent event;
     
            int maskVal = X11.SubstructureRedirectMask | X11.SubstructureNotifyMask;
            NativeLong mask = new NativeLong(maskVal);
     
            event = new X11.XClientMessageEvent();
            event.type = X11.ClientMessage;
            event.serial = new NativeLong(0);
            event.send_event = 1;
            event.message_type = ATOM_NET_WM_STATE;
            event.window = win;
            event.format = 32;
            event.data.setType(NativeLong[].class);
            event.data.l[0] = new NativeLong(_NET_WM_STATE_ADD);
            event.data.l[1] = ATOM_NET_WM_STATE_BELOW;
            event.data.l[2] = new NativeLong(0);
            event.data.l[3] = new NativeLong(0);
            event.data.l[4] = new NativeLong(0);
     
            X11.XEvent e = new X11.XEvent();
            e.setTypedValue(event);
     
            if (x11.XSendEvent(x11Display, x11RootWindow, 0, mask, e) != 0) {
     
                x11.XFlush(x11Display);
                return X11.Success;
     
            }
            else
     
                throw new Error("Cannot send " + "_NET_WM_STATE_BELOW" + " event.");
     
        }
     
     
     
        /*****************************************************************
         * FINDWINDOWIDCLASS
         * @param winsIDList
         * @param className
         * @return 
         *****************************************************************/
        public int findWindowIDClass(int[] winsIDList, String className) {
     
            X11.Window win;
            String name;
     
            for (int i = 0; i < winsIDList.length; i++) {
     
                win = new X11.Window(winsIDList[i]);
                name = getWindowClass(win);
     
                if (name.contains(className) == true )
                    return winsIDList[i];
     
            }
     
            return 0;
        }
     
     
     
        /*****************************************************************
         * FINDWINDOWIDCLASS
         * @param window
         * @return 
         *****************************************************************/
        public String getWindowClass(X11.Window window) {
     
            try {
     
                String className;
                byte[] bytes = getProperty(window, X11.XA_STRING, X11.XA_WM_CLASS);
     
                if (bytes == null)
                    throw new Error("getProperty : bytes[] = null");
     
                for (int i = 0; i < bytes.length; i++) {
     
                    if (bytes[i] == '\0') bytes[i] = '.';
     
                }
     
                className = new String(bytes, "UTF8");
     
                return className;
     
            } catch (UnsupportedEncodingException e) {
                throw new Error(e);
            }
        }
     
     
     
        /*****************************************************************
         * GETIDAllWINDOWS
         * @return 
         *****************************************************************/
        public int[] getWindowsIDList() {
     
            byte[] bytes = getProperty(x11RootWindow, X11.XA_WINDOW, ATOM_NET_CLIENT_LIST);
            int[] winsIDList = new int[bytes.length / X11.Window.SIZE];
     
            if (winsIDList.length == 0)
                throw new Error("getProperty : winsIDList[].length = 0");
     
            for (int i = 0; i < winsIDList.length; i++) {
     
                winsIDList[i] = ((bytes[3 + (X11.XID.SIZE * i)] & 0xff) << 24)
                                | ((bytes[2 + (X11.XID.SIZE * i)] & 0xff) << 16)
                                | ((bytes[1 + (X11.XID.SIZE * i)] & 0xff) << 8)
                                | ((bytes[(X11.XID.SIZE * i)] & 0xff));
     
            }
     
            return winsIDList;
     
        }
     
     
     
        /*****************************************************************
         * GETPROPERTY
         * @param window
         * @param xa_prop_type
         * @param xa_prop_name
         * @return 
         *****************************************************************/
        public byte[] getProperty(X11.Window window, X11.Atom xa_prop_type, X11.Atom xa_prop_name) {
     
            IntByReference          ret_format_ref  = new IntByReference();
            NativeLongByReference   ret_nitems_ref  = new NativeLongByReference();
            PointerByReference      ret_prop_ref    = new PointerByReference();
     
            x11.XGetWindowProperty( x11Display, window,
                                    xa_prop_name,
                                    new NativeLong(0), new NativeLong(1024),
                                    false,
                                    xa_prop_type,
                                    new X11.AtomByReference(),
                                    ret_format_ref, ret_nitems_ref,
                                    new NativeLongByReference(),
                                    ret_prop_ref);
     
            Pointer ret_prop    = ret_prop_ref.getValue();
            int ret_format      = ret_format_ref.getValue();
            long ret_nitems     = ret_nitems_ref.getValue().longValue();
     
            Map<Integer, Integer> nbytes = new HashMap<>();
            nbytes.put(32, 8);   
            nbytes.put(16, 4);   
            nbytes.put(8, 1);   
            nbytes.put(0, 0);   
     
            int length = Math.min((int) ret_nitems * nbytes.get(ret_format), 4096);
            byte[] ret  = ret_prop.getByteArray(0, length);
     
            x11.XFree(ret_prop);
     
            if (ret.length == 0)
                throw new Error("getProperty : byte[].length = 0");
     
            return ret;
        }
     
    } // END OF CLASS JavaX11Test

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Une fenêtre "sans contour", avec des contrôles
    Par Toufinet dans le forum Windows
    Réponses: 6
    Dernier message: 05/02/2011, 00h14
  2. Mettre une video en java avec Netbeans
    Par gio89 dans le forum Débuter
    Réponses: 12
    Dernier message: 04/12/2010, 13h25
  3. Donner le focus à une fenêtre non java
    Par Khyinn dans le forum Général Java
    Réponses: 2
    Dernier message: 15/05/2010, 12h40
  4. Docker une fenêtre (comme la barre des tâches)
    Par Jognu dans le forum Composants VCL
    Réponses: 1
    Dernier message: 21/01/2010, 16h47
  5. rafraichir toute une fenêtre en java
    Par nighthammer dans le forum AWT/Swing
    Réponses: 17
    Dernier message: 05/01/2006, 09h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo