Debian Codegraph @

src/script_functions.c

raw symbols SCIP
1 /**
2 * This file is part of devilspie2
3 * Copyright (C) 2011-2017 Andreas Rönnquist
4 *
5 * devilspie2 is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * devilspie2 is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with devilspie2.
17 * If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include <stdlib.h>
20
21 #define WNCK_I_KNOW_THIS_IS_UNSTABLE
22 #include <libwnck/libwnck.h>
23
24 #include <X11/Xlib.h>
25 #include <X11/Xatom.h>
26
27 #include <gdk/gdk.h>
28 #include <gdk/gdkx.h>
29
30 #include <locale.h>
31
32 #include <libintl.h>
33 #define _(String) gettext (String)
34 #define gettext_noop(String) String
35 #define N_(String) gettext_noop (String)
36
37
38 #include <lua.h>
39 #include <lualib.h>
40 #include <lauxlib.h>
41
42
43 #if (GTK_MAJOR_VERSION >= 3)
44 #define HAVE_GTK3
45 #endif
46
47
48 #include "script_functions.h"
49
50 #include "script.h"
51
52 #include "xutils.h"
53
54 #include "error_strings.h"
55
56
57 /**
58 *
59 */
60 WnckWindow *current_window = NULL;
61
62
63
64 /**
65 * returns the window name
66 */
67 int c_get_window_name(lua_State *lua)
68 {
69 int top = lua_gettop(lua);
70
71 if (top != 0) {
72 luaL_error(lua, "get_window_name: %s", no_indata_expected_error);
73 return 0;
74 }
75 char *test = NULL;
76
77 WnckWindow *window = get_current_window();
78 if (window) {
79 test = (char*)wnck_window_get_name(window);
80 } else {
81 test = "";
82 }
83
84 lua_pushstring(lua, test);
85
86 // one item returned (the window name as a string)
87 return 1;
88 }
89
90
91 /**
92 * c_get_window_name always returns a string, even if a window hasn't
93 * got a name - use this function to determine if a window really has
94 * a name or not.
95 * returns a boolean true or false
96 */
97 int c_get_window_has_name(lua_State *lua)
98 {
99 int top = lua_gettop(lua);
100
101 if (top != 0) {
102 luaL_error(lua, "get_window_has_name: %s", no_indata_expected_error);
103 return 0;
104 }
105
106 gboolean has_name = FALSE;
107
108 WnckWindow *window = get_current_window();
109
110 if (window) {
111 has_name = wnck_window_has_name(window);
112 }
113
114 lua_pushboolean(lua, has_name);
115
116 return 1;
117 }
118
119
120 /**
121 * Set the Window Geometry
122 * set_window_geometry(x,y,xsize,ysize);
123 */
124 int c_set_window_geometry(lua_State *lua)
125 {
126 int top = lua_gettop(lua);
127
128 if (top != 4) {
129 luaL_error(lua, "set_window_geometry: %s", four_indata_expected_error);
130 return 0;
131 }
132
133 int type1 = lua_type(lua, 1);
134 int type2 = lua_type(lua, 2);
135 int type3 = lua_type(lua, 3);
136 int type4 = lua_type(lua, 4);
137
138 if ((type1 != LUA_TNUMBER) ||
139 (type2 != LUA_TNUMBER) ||
140 (type3 != LUA_TNUMBER) ||
141 (type4 != LUA_TNUMBER)) {
142 luaL_error(lua, "set_window_geometry: %s", four_indata_expected_error);
143 return 0;
144 }
145
146 int x = lua_tonumber(lua, 1);
147 int y = lua_tonumber(lua, 2);
148 int xsize = lua_tonumber(lua, 3);
149 int ysize = lua_tonumber(lua, 4);
150
151 if (!devilspie2_emulate) {
152 WnckWindow *window = get_current_window();
153
154 set_window_geometry(window, x, y, xsize, ysize);
155 }
156
157 return 0;
158 }
159
160
161 /**
162 * Set the Window Geometry2
163 * set_window_geometry2(x,y,xsize,ysize);
164 */
165 int c_set_window_geometry2(lua_State *lua)
166 {
167 int top = lua_gettop(lua);
168
169 if (top != 4) {
170 luaL_error(lua,"set_window_geometry: %s", four_indata_expected_error);
171 return 0;
172 }
173
174 int type1 = lua_type(lua, 1);
175 int type2 = lua_type(lua, 2);
176 int type3 = lua_type(lua, 3);
177 int type4 = lua_type(lua, 4);
178
179 if ((type1 != LUA_TNUMBER) ||
180 (type2 != LUA_TNUMBER) ||
181 (type3 != LUA_TNUMBER) ||
182 (type4 != LUA_TNUMBER)) {
183 luaL_error(lua, "set_window_geometry: %s", four_indata_expected_error);
184 return 0;
185 }
186
187 int x = lua_tonumber(lua, 1);
188 int y = lua_tonumber(lua, 2);
189 int xsize = lua_tonumber(lua, 3);
190 int ysize = lua_tonumber(lua, 4);
191
192 if (!devilspie2_emulate) {
193 WnckWindow *window = get_current_window();
194
195 if (window) {
196 XMoveResizeWindow(gdk_x11_get_default_xdisplay(),
197 wnck_window_get_xid(window),
198 x, y,
199 xsize, ysize);
200 }
201 }
202
203 return 0;
204 }
205
206
207 /**
208 * Set the position of the window
209 */
210 int c_set_window_position(lua_State *lua)
211 {
212 int top = lua_gettop(lua);
213
214 if (top!=2) {
215 luaL_error(lua,"set_window_position: %s", two_indata_expected_error);
216 return 0;
217 }
218
219 int type1 = lua_type(lua, 1);
220 int type2 = lua_type(lua, 2);
221
222 if ((type1 != LUA_TNUMBER) || (type2 != LUA_TNUMBER)) {
223 luaL_error(lua, "set_window_position: %s", two_indata_expected_error);
224 return 0;
225 }
226
227 int x = lua_tonumber(lua, 1);
228 int y = lua_tonumber(lua, 2);
229
230 if (!devilspie2_emulate) {
231
232 WnckWindow *window = get_current_window();
233
234 if (window) {
235 wnck_window_set_geometry(window,
236 WNCK_WINDOW_GRAVITY_CURRENT,
237 WNCK_WINDOW_CHANGE_X + WNCK_WINDOW_CHANGE_Y,
238 x, y, -1, -1);
239 }
240 }
241
242 return 0;
243 }
244
245
246 /**
247 *
248 */
249 int c_set_window_position2(lua_State *lua)
250 {
251 int top = lua_gettop(lua);
252
253 if (top != 2) {
254 luaL_error(lua,"set_window_position2: %s", two_indata_expected_error);
255 return 0;
256 }
257
258 int type1 = lua_type(lua, 1);
259 int type2 = lua_type(lua, 2);
260
261 if ((type1 != LUA_TNUMBER) || (type2 != LUA_TNUMBER)) {
262 luaL_error(lua,"set_window_position2: %s", two_indata_expected_error);
263 return 0;
264 }
265
266 int x = lua_tonumber(lua,1);
267 int y = lua_tonumber(lua,2);
268
269 if (!devilspie2_emulate) {
270
271 WnckWindow *window = get_current_window();
272
273 if (window) {
274 XMoveWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
275 wnck_window_get_xid(window),
276 x, y);
277 }
278 }
279
280 return 0;
281 }
282
283
284 /**
285 * Sets the size of the window
286 */
287 int c_set_window_size(lua_State *lua)
288 {
289 int top = lua_gettop(lua);
290
291 if (top != 2) {
292 luaL_error(lua,"set_window_size: %s", two_indata_expected_error);
293 return 0;
294 }
295
296 int type1 = lua_type(lua, 1);
297 int type2 = lua_type(lua, 2);
298
299 if ((type1 != LUA_TNUMBER) || (type2 != LUA_TNUMBER)) {
300 luaL_error(lua,"set_window_size: %s", two_indata_expected_error);
301 return 0;
302 }
303
304 int x = lua_tonumber(lua,1);
305 int y = lua_tonumber(lua,2);
306
307 if (!devilspie2_emulate) {
308
309 WnckWindow *window = get_current_window();
310
311 if (window) {
312
313 devilspie2_error_trap_push();
314 wnck_window_set_geometry(window,
315 WNCK_WINDOW_GRAVITY_CURRENT,
316 WNCK_WINDOW_CHANGE_WIDTH + WNCK_WINDOW_CHANGE_HEIGHT,
317 -1, -1, x, y);
318
319 if (devilspie2_error_trap_pop()) {
320 gchar *temperror=
321 g_strdup_printf("set_window_size: %s", failed_string);
322 g_printerr("%s", temperror);
323
324 g_free(temperror);
325 }
326 }
327 }
328
329 return 0;
330 }
331
332 /**
333 * Sets the window strut
334 */
335 int c_set_window_strut(lua_State *lua)
336 {
337 int top = lua_gettop(lua);
338
339 if (top < 4) {
340 luaL_error(lua,"set_window_strut: %s", four_indata_expected_error);
341 return 0;
342 }
343
344 if (!devilspie2_emulate) {
345 #if __x86_64__
346 int64_t struts[12];
347 #else
348 int32_t struts[12];
349 #endif
350 int i;
351 for (i = 0; i < 12; i++) {
352 struts[i] = i < top ? lua_tonumber(lua, i + 1) : 0;
353 }
354
355 Display *dpy = gdk_x11_get_default_xdisplay();
356 WnckWindow *window = get_current_window();
357
358 if (window) {
359 XChangeProperty(dpy,
360 wnck_window_get_xid(window),
361 XInternAtom(dpy, "_NET_WM_STRUT_PARTIAL", False), XA_CARDINAL,
362 32,
363 PropModeReplace,
364 (unsigned char*)struts,
365 12);
366 XSync(dpy, False);
367 }
368 }
369
370 return 0;
371 }
372
373 /**
374 * Sets the window on top of all others and locks it "always on top"
375 */
376 int c_make_always_on_top(lua_State *lua)
377 {
378 int top = lua_gettop(lua);
379
380 if (top != 0) {
381 luaL_error(lua, "make_always_on_top: %s", no_indata_expected_error);
382 return 0;
383 }
384
385 if (!devilspie2_emulate) {
386 WnckWindow *window = get_current_window();
387
388 if (window) {
389 wnck_window_make_above(window);
390 }
391 }
392
393 return 0;
394 }
395
396
397 /**
398 * sets the window on top of all the others
399 */
400 int c_set_on_top(lua_State *lua)
401 {
402 int top = lua_gettop(lua);
403
404 if (top != 0) {
405 luaL_error(lua, "set_on_top: %s", no_indata_expected_error);
406 return 0;
407 }
408
409 if (!devilspie2_emulate) {
410 WnckWindow *window = get_current_window();
411
412 if (window) {
413 wnck_window_make_above(window);
414
415 wnck_window_unmake_above(window);
416 }
417 }
418
419 return 0;
420 }
421
422
423 /**
424 * returns the application name
425 */
426 int c_get_application_name(lua_State *lua)
427 {
428 int top = lua_gettop(lua);
429
430 if (top != 0) {
431 luaL_error(lua, "get_application_name: %s", no_indata_expected_error);
432 return 0;
433 }
434
435 const char *application_name;
436
437 WnckWindow *window = get_current_window();
438
439 if (window) {
440
441 WnckApplication *application=
442 wnck_window_get_application(get_current_window());
443 application_name = wnck_application_get_name(application);
444
445 } else {
446 application_name = "";
447 }
448
449 // one item returned - the application name as a string.
450 lua_pushstring(lua, application_name);
451
452 return 1;
453 }
454
455
456 /**
457 * lua_Bprint from http://www.lua.org/source/5.1/lbaselib.c.html
458 * but with the change that fputs is only called if devilspie2_debug is
459 * set to TRUE
460 */
461 int c_debug_print(lua_State *lua)
462 {
463 int n = lua_gettop(lua); /* number of arguments */
464 int i;
465 lua_getglobal(lua, "tostring");
466 for (i = 1; i <= n; i++) {
467 const char *s;
468 lua_pushvalue(lua, -1); /* function to be called */
469 lua_pushvalue(lua, i); /* value to print */
470 lua_call(lua, 1, 1);
471 s = lua_tostring(lua, -1); /* get result */
472 if (s == NULL)
473 return luaL_error(lua, LUA_QL("tostring") " must return a string to "
474 LUA_QL("print"));
475 if (i > 1) {
476 if (devilspie2_debug) fputs("\t", stdout);
477 }
478 if (devilspie2_debug) fputs(s, stdout);
479 lua_pop(lua, 1); /* pop result */
480 }
481 if (devilspie2_debug) {
482 fputs("\n", stdout);
483 fflush(stdout);
484 }
485
486 return 0;
487 }
488
489
490 /**
491 * "Shades" the window
492 */
493 int c_shade_window(lua_State *lua)
494 {
495 int top = lua_gettop(lua);
496
497 if (top != 0) {
498 luaL_error(lua,"shade_window: %s",no_indata_expected_error);
499 return 0;
500 }
501
502 if (!devilspie2_emulate) {
503 WnckWindow *window = get_current_window();
504
505 if (window) {
506
507 wnck_window_shade(window);
508 }
509 }
510
511 return 0;
512 }
513
514
515 /**
516 * "Unshades" the window
517 */
518 int c_unshade_window(lua_State *lua)
519 {
520 int top = lua_gettop(lua);
521
522 if (top != 0) {
523 luaL_error(lua,"unshade_window: %s");
524 return 0;
525 }
526
527 if (!devilspie2_emulate) {
528 WnckWindow *window = get_current_window();
529
530 if (window) {
531
532 wnck_window_unshade(window);
533 }
534 }
535
536 return 0;
537 }
538
539
540 /**
541 * Minimizes the window
542 */
543 int c_minimize_window(lua_State *lua)
544 {
545 int top = lua_gettop(lua);
546
547 if (top != 0) {
548 luaL_error(lua,"minimize_window: %s",no_indata_expected_error);
549 return 0;
550 }
551
552 if (!devilspie2_emulate) {
553 WnckWindow *window = get_current_window();
554
555 if (window) {
556
557 wnck_window_minimize(window);
558 }
559 }
560
561 return 0;
562 }
563
564
565 /**
566 * unminimizes window
567 */
568 int c_unminimize_window(lua_State *lua)
569 {
570 int top = lua_gettop(lua);
571
572 if (top != 0) {
573 luaL_error(lua,"unminimize_window: %s",no_indata_expected_error);
574 return 0;
575 }
576
577 if (!devilspie2_emulate) {
578 WnckWindow *window = get_current_window();
579
580 if (window) {
581 wnck_window_unminimize (window, GDK_CURRENT_TIME);
582 }
583 }
584
585 return 0;
586 }
587
588
589 /**
590 * sets the window that the scripts are affecting
591 */
592 void set_current_window(WnckWindow *window)
593 {
594 current_window=window;
595 }
596
597
598 /**
599 * gets the window that the scripts are affecting
600 */
601 WnckWindow *get_current_window()
602 {
603 return current_window;
604 }
605
606
607 /**
608 * Decorates a window
609 */
610 int c_undecorate_window(lua_State *lua)
611 {
612 gboolean result = TRUE;
613 int top = lua_gettop(lua);
614
615 if (top != 0) {
616 luaL_error(lua,"undecorate_window: %s",no_indata_expected_error);
617 return 0;
618 }
619
620 if (!devilspie2_emulate) {
621 WnckWindow *window = get_current_window();
622
623 if (window) {
624 if (!devilspie2_emulate) {
625
626 gulong xid = wnck_window_get_xid(window);
627
628 if (!undecorate_window(xid)) {
629 result=FALSE;
630 }
631 }
632 }
633 }
634
635 lua_pushboolean(lua,result);
636
637 return 1;
638 }
639
640
641 /**
642 * undecorates a window
643 */
644 int c_decorate_window(lua_State *lua)
645 {
646 gboolean result = TRUE;
647 int top = lua_gettop(lua);
648
649 if (top != 0) {
650 luaL_error(lua,"decorate_window: %s",no_indata_expected_error);
651 return 0;
652 }
653
654 if (!devilspie2_emulate) {
655 WnckWindow *window = get_current_window();
656
657 if (window) {
658
659 if (!devilspie2_emulate) {
660
661 gulong xid = wnck_window_get_xid(window);
662
663 if (!decorate_window(xid)) {
664 result=FALSE;
665 }
666 }
667 }
668 }
669
670 lua_pushboolean(lua,result);
671
672 return 1;
673 }
674
675
676
677 /**
678 * Move a window to a specific workspace
679 */
680 int c_set_window_workspace(lua_State *lua)
681 {
682 int top = lua_gettop(lua);
683
684 if (top != 1) {
685 luaL_error(lua,"set_window_workspace: %s", one_indata_expected_error);
686 return 0;
687 }
688
689 int type = lua_type(lua, 1);
690
691 if (type!=LUA_TNUMBER) {
692 luaL_error(lua, "set_window_workspace: %s",
693 number_expected_as_indata_error);
694 return 0;
695 }
696
697 int number = lua_tonumber(lua, 1);
698
699 WnckWindow *window = get_current_window();
700
701 if (window) {
702 WnckScreen *screen;
703 WnckWorkspace *workspace;
704
705 screen = wnck_window_get_screen(window);
706 workspace = wnck_screen_get_workspace(screen, number-1);
707
708 if (!workspace) {
709 g_warning(_("Workspace number %d does not exist!"), number);
710 }
711 if (!devilspie2_emulate) {
712 wnck_window_move_to_workspace(window, workspace);
713 }
714 }
715
716 lua_pushboolean(lua,TRUE);
717
718 return 1;
719 }
720
721
722
723
724 /**
725 * Makes a workspace the active one
726 */
727 int c_change_workspace(lua_State *lua)
728 {
729 int top = lua_gettop(lua);
730 GTimeVal timestamp;
731
732 if (top != 1) {
733 luaL_error(lua,"change_workspace: %s", one_indata_expected_error);
734 return 0;
735 }
736
737 int type = lua_type(lua, 1);
738
739 if (type!=LUA_TNUMBER) {
740 luaL_error(lua,"change_workspace: %s", number_expected_as_indata_error);
741 return 0;
742 }
743
744 int number = lua_tonumber(lua, 1);
745
746 WnckWindow *window = get_current_window();
747 if (window) {
748 WnckScreen *screen;
749 WnckWorkspace *workspace;
750
751 screen = wnck_window_get_screen(window);
752 workspace = wnck_screen_get_workspace(screen, number-1);
753
754 if (!workspace) {
755 g_warning(_("Workspace number %d does not exist!"), number);
756 }
757
758 g_get_current_time(&timestamp);
759 if (!devilspie2_emulate) {
760 wnck_workspace_activate(workspace, timestamp.tv_sec);
761 }
762 }
763
764 lua_pushboolean(lua, TRUE);
765
766 return 1;
767 }
768
769
770 /**
771 * Return workspace count
772 */
773 int c_get_workspace_count(lua_State *lua)
774 {
775 int count = 0;
776 int top = lua_gettop(lua);
777
778 if (top != 0) {
779 luaL_error(lua, "get_workspace_count: %s", no_indata_expected_error);
780 return 0;
781 }
782
783 WnckWindow *window = get_current_window();
784
785 if (window) {
786 WnckScreen *screen;
787
788 screen = wnck_window_get_screen(window);
789 count = wnck_screen_get_workspace_count(screen);
790 }
791
792 lua_pushnumber(lua, count);
793
794 return 1;
795 }
796
797
798 /**
799 * Unmaximize window
800 */
801 int c_unmaximize_window(lua_State *lua)
802 {
803 int top = lua_gettop(lua);
804
805 if (top != 0) {
806 luaL_error(lua, "unmaximize: %s", no_indata_expected_error);
807 return 0;
808 }
809
810 if (!devilspie2_emulate) {
811 WnckWindow *window = get_current_window();
812 if (window) {
813 wnck_window_unmaximize(window);
814 }
815 }
816
817 return 0;
818 }
819
820
821 /**
822 * Maximize Window
823 */
824 int c_maximize_window(lua_State *lua)
825 {
826 int top = lua_gettop(lua);
827
828 if (top != 0) {
829 luaL_error(lua, "maximize: %s", no_indata_expected_error);
830 return 0;
831 }
832
833 if (!devilspie2_emulate) {
834 WnckWindow *window = get_current_window();
835 if (window) {
836 wnck_window_maximize(window);
837 }
838 }
839 return 0;
840 }
841
842
843 /**
844 * Maximize Window Vertically
845 */
846 int c_maximize_window_vertically(lua_State *lua)
847 {
848 int top = lua_gettop(lua);
849
850 if (top != 0) {
851 luaL_error(lua, "maximize_vertically: %s", no_indata_expected_error);
852 return 0;
853 }
854
855 if (!devilspie2_emulate) {
856 WnckWindow *window = get_current_window();
857 if (window) {
858 wnck_window_maximize_vertically(window);
859 }
860 }
861
862 return 0;
863 }
864
865
866 /**
867 * Maximize the window horisontally
868 */
869 int c_maximize_window_horisontally(lua_State *lua)
870 {
871 int top = lua_gettop(lua);
872
873 if (top != 0) {
874 luaL_error(lua, "maximize_horisontally: %s", no_indata_expected_error);
875 return 0;
876 }
877
878 if (!devilspie2_emulate) {
879 WnckWindow *window = get_current_window();
880 if (window) {
881 wnck_window_maximize_horizontally(window);
882 }
883 }
884
885 return 0;
886 }
887
888
889
890 /**
891 * Pins the window
892 */
893 int c_pin_window(lua_State *lua)
894 {
895 int top = lua_gettop(lua);
896
897 if (top != 0) {
898 luaL_error(lua, "pin_window: %s", no_indata_expected_error);
899 return 0;
900 }
901
902 if (!devilspie2_emulate) {
903 WnckWindow *window = get_current_window();
904 if (window) {
905 wnck_window_pin(window);
906 }
907 }
908
909 return 0;
910 }
911
912
913
914 /**
915 * Unpin the window
916 */
917 int c_unpin_window(lua_State *lua)
918 {
919 int top = lua_gettop(lua);
920
921 if (top != 0) {
922 luaL_error(lua, "unpin_window: %s", no_indata_expected_error);
923 return 0;
924 }
925
926 if (!devilspie2_emulate) {
927 WnckWindow *window = get_current_window();
928 if (window) {
929 wnck_window_unpin(window);
930 }
931 }
932
933 return 0;
934 }
935
936
937 /**
938 * Sticks the window
939 */
940 int c_stick_window(lua_State *lua)
941 {
942 int top = lua_gettop(lua);
943
944 if (top != 0) {
945 luaL_error(lua, "stick_window: %s", no_indata_expected_error);
946 return 0;
947 }
948
949 if (!devilspie2_emulate) {
950 WnckWindow *window = get_current_window();
951 if (window) {
952 wnck_window_stick(window);
953 }
954 }
955
956 return 0;
957 }
958
959
960 /**
961 * Unstick the window
962 */
963 int c_unstick_window(lua_State *lua)
964 {
965 int top = lua_gettop(lua);
966
967 if (top != 0) {
968 luaL_error(lua, "unstick_window: %s", no_indata_expected_error);
969 return 0;
970 }
971
972 if (!devilspie2_emulate) {
973 WnckWindow *window = get_current_window();
974 if (window) {
975 wnck_window_unstick(window);
976 }
977 }
978
979 return 0;
980 }
981
982
983 /**
984 * return the geometry of the current window to the Lua script
985 */
986 int c_get_window_geometry(lua_State *lua)
987 {
988 int top = lua_gettop(lua);
989
990 if (top != 0) {
991 luaL_error(lua, "get_window_geometry: %s", no_indata_expected_error);
992 return 0;
993 }
994
995 int x, y, width, height;
996
997 WnckWindow *window = get_current_window();
998 if (window)
999 {
1000 wnck_window_get_geometry(window, &x, &y, &width, &height);
1001 }
1002
1003 lua_pushnumber(lua, x);
1004 lua_pushnumber(lua, y);
1005 lua_pushnumber(lua, width);
1006 lua_pushnumber(lua, height);
1007
1008 return 4;
1009 }
1010
1011
1012 /**
1013 * return the client geometry of the current window to the Lua script
1014 * this is excluding the window manager frame
1015 */
1016 int c_get_client_window_geometry(lua_State *lua)
1017 {
1018 int top = lua_gettop(lua);
1019
1020 if (top != 0) {
1021 luaL_error(lua, "get_client_window_geometry: %s", no_indata_expected_error);
1022 return 0;
1023 }
1024
1025 int x, y, width, height;
1026
1027 WnckWindow *window = get_current_window();
1028 if (window)
1029 {
1030 wnck_window_get_client_window_geometry(window, &x, &y, &width, &height);
1031 }
1032
1033 lua_pushnumber(lua, x);
1034 lua_pushnumber(lua, y);
1035 lua_pushnumber(lua, width);
1036 lua_pushnumber(lua, height);
1037
1038 return 4;
1039 }
1040
1041
1042 /**
1043 *
1044 */
1045 int c_set_skip_tasklist(lua_State *lua)
1046 {
1047 int top = lua_gettop(lua);
1048
1049 if (top != 1) {
1050 luaL_error(lua, "set_skip_tasklist: %s", one_indata_expected_error);
1051 return 0;
1052 }
1053
1054 int type = lua_type(lua, 1);
1055
1056 if (type != LUA_TBOOLEAN) {
1057 luaL_error(lua, "set_skip_tasklist: %s", boolean_expected_as_indata_error);
1058 return 0;
1059 }
1060
1061 int value = lua_toboolean(lua, 1);
1062
1063 gboolean skip_tasklist = (gboolean)(value);
1064
1065 if (!devilspie2_emulate) {
1066 WnckWindow *window = get_current_window();
1067 if (window) {
1068 wnck_window_set_skip_tasklist(window, skip_tasklist);
1069 }
1070 }
1071
1072 return 0;
1073 }
1074
1075
1076 /**
1077 *
1078 */
1079 int c_set_skip_pager(lua_State *lua)
1080 {
1081 int top = lua_gettop(lua);
1082
1083 if (top != 1) {
1084 luaL_error(lua, "set_skip_pager: %s", one_indata_expected_error);
1085 return 0;
1086 }
1087
1088 int type = lua_type(lua, 1);
1089
1090 if (type != LUA_TBOOLEAN) {
1091 luaL_error(lua, "set_skip_pager: %s", boolean_expected_as_indata_error);
1092 return 0;
1093 }
1094
1095 int value = lua_toboolean(lua, 1);
1096
1097 gboolean skip_pager = (gboolean)(value);
1098
1099 if (!devilspie2_emulate) {
1100 WnckWindow *window = get_current_window();
1101 if (window) {
1102 wnck_window_set_skip_pager(window, skip_pager);
1103 }
1104 }
1105
1106 return 0;
1107 }
1108
1109
1110 /**
1111 *
1112 */
1113 int c_get_window_is_maximized(lua_State *lua)
1114 {
1115 int top = lua_gettop(lua);
1116
1117 if (top != 0) {
1118 luaL_error(lua, "get_window_is__maximized: %s",
1119 no_indata_expected_error);
1120 return 0;
1121 }
1122
1123 WnckWindow *window = get_current_window();
1124
1125 gboolean is_maximized = FALSE;
1126 if (window) {
1127 is_maximized = wnck_window_is_maximized(window);
1128 }
1129
1130 lua_pushboolean(lua, is_maximized);
1131
1132 return 1;
1133 }
1134
1135 /**
1136 *
1137 */
1138 int c_get_window_is_maximized_vertically(lua_State *lua)
1139 {
1140 int top = lua_gettop(lua);
1141
1142 if (top != 0) {
1143 luaL_error(lua, "get_window_is_horisontally_maximized: %s",
1144 no_indata_expected_error);
1145 return 0;
1146 }
1147
1148 WnckWindow *window = get_current_window();
1149
1150 gboolean is_vertically_maximized = FALSE;
1151 if (window) {
1152 is_vertically_maximized = wnck_window_is_maximized_vertically(window);
1153 }
1154
1155 lua_pushboolean(lua, is_vertically_maximized);
1156
1157 return 1;
1158 }
1159
1160
1161 /**
1162 *
1163 */
1164 int c_get_window_is_maximized_horisontally(lua_State *lua)
1165 {
1166 int top = lua_gettop(lua);
1167
1168 if (top != 0) {
1169 luaL_error(lua, "get_window_is_horisontally_maximized: %s",
1170 no_indata_expected_error);
1171 return 0;
1172 }
1173
1174 WnckWindow *window = get_current_window();
1175
1176 gboolean is_horisontally_maximized = FALSE;
1177 if (window) {
1178 is_horisontally_maximized = wnck_window_is_maximized_horizontally(window);
1179 }
1180
1181 lua_pushboolean(lua, is_horisontally_maximized);
1182
1183 return 1;
1184 }
1185
1186
1187 /**
1188 *
1189 */
1190 int c_get_window_is_pinned(lua_State *lua)
1191 {
1192 int top = lua_gettop(lua);
1193
1194 if (top != 0) {
1195 luaL_error(lua, "get_window_is_pinned: %s",
1196 no_indata_expected_error);
1197 return 0;
1198 }
1199
1200 WnckWindow *window = get_current_window();
1201
1202 gboolean is_pinned = FALSE;
1203 if (window) {
1204 is_pinned = wnck_window_is_pinned(window);
1205 }
1206
1207 lua_pushboolean(lua, is_pinned);
1208
1209 return 1;
1210 }
1211
1212
1213 /**
1214 *
1215 */
1216 int c_set_window_above(lua_State *lua)
1217 {
1218 int top = lua_gettop(lua);
1219 gboolean set_above;
1220
1221 if (top > 1) {
1222 luaL_error(lua, "set_window_above: %s", one_indata_expected_error);
1223 return 0;
1224 }
1225 else if (top == 1) {
1226 int type = lua_type(lua, 1);
1227
1228 if (type != LUA_TBOOLEAN) {
1229 luaL_error(lua, "set_window_above: %s", boolean_expected_as_indata_error);
1230 return 0;
1231 }
1232
1233 int value = lua_toboolean(lua, 1);
1234 set_above = (gboolean)(value);
1235 }
1236 else {
1237 set_above = TRUE;
1238 }
1239
1240 WnckWindow *window = get_current_window();
1241 if (!devilspie2_emulate) {
1242 Window xid = wnck_window_get_xid(window);
1243 devilspie2_change_state(devilspie2_window_get_xscreen(xid),
1244 xid,
1245 set_above,
1246 my_wnck_atom_get("_NET_WM_STATE_ABOVE"),
1247 0);
1248 }
1249
1250 return 0;
1251 }
1252
1253
1254 /**
1255 *
1256 */
1257 int c_set_window_below(lua_State *lua)
1258 {
1259 int top = lua_gettop(lua);
1260 gboolean set_below;
1261
1262 if (top > 1) {
1263 luaL_error(lua, "set_window_below: %s", one_indata_expected_error);
1264 return 0;
1265 }
1266 else if (top == 1) {
1267 int type = lua_type(lua, 1);
1268
1269 if (type != LUA_TBOOLEAN) {
1270 luaL_error(lua, "set_window_below: %s", boolean_expected_as_indata_error);
1271 return 0;
1272 }
1273
1274 int value = lua_toboolean(lua, 1);
1275 set_below = (gboolean)(value);
1276 }
1277 else {
1278 set_below = TRUE;
1279 }
1280
1281 WnckWindow *window = get_current_window();
1282 if (!devilspie2_emulate) {
1283
1284 Window xid = wnck_window_get_xid(window);
1285 devilspie2_change_state(devilspie2_window_get_xscreen(xid),
1286 xid,
1287 set_below,
1288 my_wnck_atom_get("_NET_WM_STATE_BELOW"),
1289 0);
1290 }
1291
1292 return 0;
1293 }
1294
1295
1296 /**
1297 *
1298 */
1299 int c_get_window_type(lua_State *lua)
1300 {
1301 int top = lua_gettop(lua);
1302
1303 if (top != 0) {
1304 luaL_error(lua, "get_window_type: %s", no_indata_expected_error);
1305 return 0;
1306 }
1307
1308 WnckWindow *window = get_current_window();
1309
1310 gchar *window_type_string = NULL;
1311
1312 if (window) {
1313 WnckWindowType window_type = wnck_window_get_window_type(window);
1314
1315 switch (window_type) {
1316 case WNCK_WINDOW_NORMAL:
1317 window_type_string = g_strdup("WINDOW_TYPE_NORMAL");
1318 break;
1319 case WNCK_WINDOW_DESKTOP:
1320 window_type_string = g_strdup("WINDOW_TYPE_DESKTOP");
1321 break;
1322 case WNCK_WINDOW_DOCK:
1323 window_type_string = g_strdup("WINDOW_TYPE_DOCK");
1324 break;
1325 case WNCK_WINDOW_DIALOG:
1326 window_type_string = g_strdup("WINDOW_TYPE_DIALOG");
1327 break;
1328 case WNCK_WINDOW_TOOLBAR:
1329 window_type_string = g_strdup("WINDOW_TYPE_TOOLBAR");
1330 break;
1331 case WNCK_WINDOW_MENU:
1332 window_type_string = g_strdup("WINDOW_TYPE_MENU");
1333 break;
1334 case WNCK_WINDOW_UTILITY:
1335 window_type_string = g_strdup("WINDOW_TYPE_UTILITY");
1336 break;
1337 case WNCK_WINDOW_SPLASHSCREEN:
1338 window_type_string = g_strdup("WINDOW_TYPE_SPLASHSCREEN");
1339 break;
1340 default:
1341 window_type_string = g_strdup("WINDOW_TYPE_UNRECOGNIZED");
1342 };
1343 } else {
1344 window_type_string = g_strdup("WINDOW_ERROR");
1345 }
1346
1347 lua_pushstring(lua, window_type_string);
1348
1349 g_free(window_type_string);
1350
1351 return 1;
1352 }
1353
1354
1355 #ifdef HAVE_GTK3
1356 /**
1357 * c_get_class_instance_name
1358 * Only available on libwnck 3+
1359 */
1360 int c_get_class_instance_name(lua_State *lua)
1361 {
1362 int top = lua_gettop(lua);
1363
1364 if (top != 0) {
1365 luaL_error(lua, "get_window_class_instance_name: %s",
1366 no_indata_expected_error);
1367 return 0;
1368 }
1369
1370 const char *class_instance_name;
1371
1372 WnckWindow *window = get_current_window();
1373
1374 if (window) {
1375 class_instance_name = wnck_window_get_class_instance_name(window);
1376
1377 } else {
1378 class_instance_name="";
1379 }
1380
1381 // one item returned - the window class instance name as a string.
1382 lua_pushstring(lua, class_instance_name);
1383
1384 return 1;
1385 }
1386
1387 #endif
1388
1389
1390 /**
1391 *
1392 */
1393 int c_get_window_property(lua_State *lua)
1394 {
1395 int top = lua_gettop(lua);
1396
1397 if (top != 1) {
1398 luaL_error(lua, "get_window_property: %s", one_indata_expected_error);
1399 return 0;
1400 }
1401
1402 // gchar *property=
1403 int type = lua_type(lua, 1);
1404
1405 if (type != LUA_TSTRING) {
1406 luaL_error(lua, "get_window_property: %s", string_expected_as_indata_error);
1407 return 0;
1408 }
1409
1410 const gchar *value = lua_tostring(lua, 1);
1411
1412 WnckWindow *window = get_current_window();
1413
1414 gchar *result = NULL;
1415
1416 if (window) {
1417 result = my_wnck_get_string_property_latin1(wnck_window_get_xid(window),
1418 my_wnck_atom_get(value));
1419 } else {
1420 result = g_strdup_printf("NO RESULT");
1421 }
1422
1423 if (result) {
1424 lua_pushstring(lua, result);
1425 } else {
1426 lua_pushstring(lua, "");
1427 }
1428
1429 g_free(result);
1430
1431 return 1;
1432 }
1433
1434
1435 /**
1436 *
1437 */
1438 int c_get_window_role(lua_State *lua)
1439 {
1440 int top = lua_gettop(lua);
1441
1442 if (top != 0) {
1443 luaL_error(lua, "get_window_role: %s", no_indata_expected_error);
1444 return 0;
1445 }
1446
1447 WnckWindow *window = get_current_window();
1448
1449 gchar *result = NULL;
1450
1451 if (window) {
1452 result = my_wnck_get_string_property_latin1(wnck_window_get_xid(window),
1453 my_wnck_atom_get("WM_WINDOW_ROLE"));
1454 }
1455
1456 if (result) {
1457 lua_pushstring(lua, result);
1458 } else {
1459 lua_pushstring(lua, "");
1460 }
1461
1462 g_free(result);
1463
1464 return 1;
1465 }
1466
1467
1468 /**
1469 *
1470 */
1471 int c_get_window_xid(lua_State *lua)
1472 {
1473 int top = lua_gettop(lua);
1474
1475 if (top != 0) {
1476 luaL_error(lua, "get_window_xid: %s", no_indata_expected_error);
1477 return 0;
1478 }
1479
1480 WnckWindow *window = get_current_window();
1481
1482 gulong result;
1483
1484 if (window) {
1485 result = wnck_window_get_xid(window);
1486 } else {
1487 result = 0;
1488 }
1489
1490 lua_pushnumber(lua, result);
1491
1492 return 1;
1493 }
1494
1495
1496 /**
1497 *
1498 */
1499 int c_get_window_class(lua_State *lua)
1500 {
1501 int top = lua_gettop(lua);
1502
1503 if (top != 0) {
1504 luaL_error(lua, "get_window_class: %s", no_indata_expected_error);
1505 return 0;
1506 }
1507
1508 WnckWindow *window = get_current_window();
1509
1510 gchar *result;
1511
1512 if (window) {
1513 WnckClassGroup *class_group = wnck_window_get_class_group(window);
1514
1515 #ifdef WNCK_MAJOR_VERSION
1516 #if WNCK_CHECK_VERSION(3,2,0)
1517 gchar *class_name = (char*)wnck_class_group_get_id(class_group);
1518 #else
1519 gchar *class_name = (char*)wnck_class_group_get_res_class (class_group);
1520 #endif
1521 #else
1522 gchar *class_name = (char*)wnck_class_group_get_res_class (class_group);
1523 #endif
1524
1525 result = g_strdup(class_name);
1526
1527 } else {
1528 result = g_strdup("");
1529 }
1530
1531 lua_pushstring(lua, result);
1532
1533 g_free(result);
1534
1535 return 1;
1536 }
1537
1538
1539 /**
1540 *
1541 */
1542 int c_set_window_fullscreen(lua_State *lua)
1543 {
1544 int top = lua_gettop(lua);
1545
1546 if (top != 1) {
1547 luaL_error(lua, "set_window_fullscreen: %s",
1548 one_indata_expected_error);
1549 return 0;
1550 }
1551
1552 WnckWindow *window = get_current_window();
1553
1554 int type = lua_type(lua, 1);
1555
1556 if (type != LUA_TBOOLEAN) {
1557 luaL_error(lua, "set_window_fullscreen: %s",
1558 boolean_expected_as_indata_error);
1559 return 0;
1560 }
1561
1562 gboolean fullscreen = lua_toboolean(lua, 1);
1563
1564 if (window) {
1565 if (!devilspie2_emulate) {
1566 wnck_window_set_fullscreen(window, fullscreen);
1567 }
1568 }
1569
1570
1571 return 0;
1572 }
1573
1574
1575 /**
1576 *
1577 */
1578 int c_set_viewport(lua_State *lua)
1579 {
1580 int top = lua_gettop(lua);
1581 int width, height;
1582 int viewport_start_x, viewport_start_y;
1583 int win_x, win_y;
1584
1585 if (top == 1) {
1586
1587 WnckScreen *screen;
1588 int x;
1589 int type = lua_type(lua, 1);
1590 if (type != LUA_TNUMBER) {
1591 luaL_error(lua, "set_viewport: %s", number_expected_as_indata_error);
1592 return 0;
1593 }
1594
1595 int num = lua_tonumber(lua,1);
1596
1597 if (num <= 0) {
1598 g_error("set_viewport: %s", integer_greater_than_zero_expected_error);
1599 lua_pushboolean(lua, FALSE);
1600 return 1;
1601 }
1602
1603 WnckWindow *window = get_current_window();
1604
1605 if (!window) {
1606 lua_pushboolean(lua, FALSE);
1607 return 1;
1608 }
1609
1610 screen = wnck_window_get_screen(window);
1611
1612 wnck_window_get_geometry(window, &win_x, &win_y, &width, &height);
1613
1614 gulong xid = wnck_window_get_xid(window);
1615
1616 //viewport_start = devilspie2_get_viewport_start(xid);
1617 if (devilspie2_get_viewport_start(xid, &viewport_start_x, &viewport_start_y) != 0) {
1618 g_printerr("set_viewport: %s", could_not_find_current_viewport_error);
1619 lua_pushboolean(lua, FALSE);
1620 return 1;
1621 }
1622
1623 x = ((num - 1) * wnck_screen_get_width(screen)) - viewport_start_x + win_x;
1624
1625 devilspie2_error_trap_push();
1626 XMoveResizeWindow(gdk_x11_get_default_xdisplay(),
1627 wnck_window_get_xid(window),
1628 x, win_y, width, height);
1629
1630 if (devilspie2_error_trap_pop()) {
1631 g_printerr("set_viewport: %s", setting_viewport_failed_error);
1632 lua_pushboolean(lua, FALSE);
1633 return 1;
1634 }
1635
1636 lua_pushboolean(lua, TRUE);
1637 return 1;
1638
1639 } else if (top == 2) {
1640
1641 int type1 = lua_type(lua, 1);
1642 int type2 = lua_type(lua, 2);
1643
1644 if (type1 != LUA_TNUMBER) {
1645 luaL_error(lua, "set_viewport: %s", number_expected_as_indata_error);
1646 return 0;
1647 }
1648
1649 if (type2 != LUA_TNUMBER) {
1650 luaL_error(lua, "set_viewport: %s", number_expected_as_indata_error);
1651 return 0;
1652 }
1653
1654 int new_xpos = lua_tonumber(lua, 1);
1655 int new_ypos = lua_tonumber(lua, 2);
1656
1657 WnckWindow *window = get_current_window();
1658
1659 if (!window) {
1660 lua_pushboolean(lua, FALSE);
1661 return 1;
1662 }
1663
1664 wnck_window_get_geometry(window, &win_x, &win_y, &width, &height);
1665
1666 gulong xid = wnck_window_get_xid(window);
1667
1668 //viewport_start = devilspie2_get_viewport_start(xid);
1669 if (devilspie2_get_viewport_start(xid, &viewport_start_x, &viewport_start_y) != 0) {
1670 g_printerr("set_viewport: %s", could_not_find_current_viewport_error);
1671 lua_pushboolean(lua, FALSE);
1672 return 1;
1673 }
1674
1675 devilspie2_error_trap_push();
1676 XMoveResizeWindow(gdk_x11_get_default_xdisplay(),
1677 wnck_window_get_xid(window),
1678 new_xpos, new_ypos, width, height);
1679
1680 if (devilspie2_error_trap_pop()) {
1681 g_printerr("set_viewport: %s", setting_viewport_failed_error);
1682 lua_pushboolean(lua, FALSE);
1683 return 1;
1684 }
1685
1686 lua_pushboolean(lua, TRUE);
1687 return 1;
1688
1689
1690 } else {
1691 luaL_error(lua, "set_viewport: %s", one_or_two_indata_expected_error);
1692 return 0;
1693 }
1694
1695 return 0;
1696 }
1697
1698
1699 /**
1700 *
1701 */
1702 int c_center(lua_State *lua)
1703 {
1704 int top = lua_gettop(lua);
1705
1706 int workspace_width, workspace_height, window_width, window_height;
1707 int xoffset, yoffset;
1708 WnckScreen *screen;
1709 WnckWorkspace *workspace;
1710
1711 if (top != 0) {
1712 luaL_error(lua, "center: %s", no_indata_expected_error);
1713 return 0;
1714 }
1715
1716 WnckWindow *window = get_current_window();
1717
1718 if (!window) {
1719 lua_pushboolean(lua, FALSE);
1720 return 1;
1721 }
1722
1723 wnck_window_get_geometry(window, NULL, NULL, &window_width, &window_height);
1724
1725 screen = wnck_window_get_screen(window);
1726
1727 workspace = wnck_screen_get_active_workspace(screen);
1728
1729 if (workspace == NULL) {
1730 workspace = wnck_screen_get_workspace(screen,0);
1731 }
1732
1733 if (workspace == NULL) {
1734 g_printerr(_("Could not get workspace"));
1735 lua_pushboolean(lua, FALSE);
1736 return 1;
1737 }
1738
1739 workspace_width = wnck_workspace_get_width(workspace);
1740 workspace_height = wnck_workspace_get_height(workspace);
1741
1742 xoffset = (workspace_width - window_width) / 2;
1743 yoffset = (workspace_height - window_height) / 2;
1744
1745 devilspie2_error_trap_push();
1746 XMoveWindow (gdk_x11_get_default_xdisplay(),
1747 wnck_window_get_xid(window),
1748 xoffset, yoffset);
1749
1750 if (devilspie2_error_trap_pop()) {
1751 g_printerr("center: %s", failed_string);
1752 lua_pushboolean(lua, FALSE);
1753 return 1;
1754 }
1755
1756 lua_pushboolean(lua, TRUE);
1757
1758 return 1;
1759 }
1760
1761
1762 /**
1763 *
1764 */
1765 int c_set_opacity(lua_State *lua)
1766 {
1767
1768 int top = lua_gettop(lua);
1769 //WnckScreen *screen;
1770
1771 if (top != 1) {
1772 luaL_error(lua, "set_opacity: %s", one_indata_expected_error);
1773 return 0;
1774 }
1775
1776 int type = lua_type(lua, 1);
1777 if (type != LUA_TNUMBER) {
1778 luaL_error(lua, "set_opacity: %s", number_expected_as_indata_error);
1779 return 0;
1780 }
1781
1782 double value = (double)lua_tonumber(lua, 1);
1783
1784 WnckWindow *window = get_current_window();
1785 gulong xid = wnck_window_get_xid(window);
1786
1787 if (window)
1788 my_window_set_opacity(xid, value);
1789
1790 return 0;
1791 }
1792
1793
1794 /**
1795 *
1796 */
1797 int c_set_window_type(lua_State *lua)
1798 {
1799 int top = lua_gettop(lua);
1800
1801 if (top != 1) {
1802 luaL_error(lua, "set_window_type: %s", one_indata_expected_error);
1803 return 0;
1804 }
1805
1806 int type = lua_type(lua, 1);
1807 if (type != LUA_TSTRING) {
1808 luaL_error(lua, "set_window_type: %s", string_expected_as_indata_error);
1809 return 0;
1810 }
1811
1812 gchar *indata = (gchar*)lua_tostring(lua, 1);
1813
1814 WnckWindow *window = get_current_window();
1815
1816 if (window) {
1817 gulong xid = wnck_window_get_xid(window);
1818 my_window_set_window_type(xid, indata);
1819 }
1820
1821 return 0;
1822 }
1823
1824
1825 /**
1826 * return the geometry of the screen to the Lua script
1827 */
1828 int c_get_screen_geometry(lua_State *lua)
1829 {
1830 int top = lua_gettop(lua);
1831
1832 if (top != 0) {
1833 luaL_error(lua, "get_screen_geometry: %s", no_indata_expected_error);
1834 return 0;
1835 }
1836
1837 int width = -1, height = -1;
1838 WnckWindow *window = get_current_window();
1839
1840 if (window) {
1841 WnckScreen *screen;
1842 screen = wnck_window_get_screen(window);
1843 width = wnck_screen_get_width(screen);
1844 height = wnck_screen_get_height(screen);
1845 }
1846
1847 lua_pushnumber(lua, width);
1848 lua_pushnumber(lua, height);
1849
1850 return 2;
1851 }
1852
1853
1854 /**
1855 *
1856 */
1857 int c_focus(lua_State *lua)
1858 {
1859 int top = lua_gettop(lua);
1860 if (top != 0) {
1861 luaL_error(lua, "focus: %s", no_indata_expected_error);
1862 return 0;
1863 }
1864
1865 WnckWindow *window = get_current_window();
1866
1867 if (window) {
1868 wnck_window_activate(window, GDK_CURRENT_TIME);
1869 }
1870
1871 return 0;
1872 }
1873
1874
1875 /**
1876 *
1877 */
1878 int c_close_window(lua_State *lua)
1879 {
1880 int top = lua_gettop(lua);
1881 if (top != 0) {
1882 luaL_error(lua, "close_window: %s", no_indata_expected_error);
1883 return 0;
1884 }
1885
1886 WnckWindow *window = get_current_window();
1887 if (window) {
1888 wnck_window_close(window, GDK_CURRENT_TIME);
1889 }
1890
1891 return 0;
1892 }
1893
1894
1895 /**
1896 *
1897 */
1898 int c_get_window_fullscreen(lua_State *lua)
1899 {
1900 int top = lua_gettop(lua);
1901 if (top != 0) {
1902 luaL_error(lua, "is_fullscreen: %s", no_indata_expected_error);
1903 return 0;
1904 }
1905
1906 gboolean result = FALSE;
1907
1908 WnckWindow *window = get_current_window();
1909 if (window) {
1910 result = wnck_window_is_fullscreen(window);
1911 }
1912
1913 lua_pushboolean(lua, result);
1914
1915 return 1;
1916 }
1917
1918
1919 /**
1920 *
1921 */
1922 int c_xy(lua_State *lua)
1923 {
1924 int top = lua_gettop(lua);
1925
1926 if (top == 0) {
1927 // return the xy coordinates of the window
1928
1929 WnckWindow *window = get_current_window();
1930 if (window != NULL) {
1931
1932 int x, y, width, height;
1933
1934 wnck_window_get_geometry(window, &x, &y, &width, &height);
1935
1936 lua_pushnumber(lua, x);
1937 lua_pushnumber(lua, y);
1938
1939 return 2;
1940 }
1941
1942 } else if (top == 2) {
1943 // set the coordinates of the window
1944
1945 int type1 = lua_type(lua, 1);
1946 int type2 = lua_type(lua, 2);
1947
1948 if ((type1 != LUA_TNUMBER) ||
1949 (type2 != LUA_TNUMBER)) {
1950 luaL_error(lua, "xy: %s", two_indata_expected_error);
1951 return 0;
1952 }
1953
1954 int x = lua_tonumber(lua, 1);
1955 int y = lua_tonumber(lua, 2);
1956
1957 if (!devilspie2_emulate) {
1958
1959 WnckWindow *window = get_current_window();
1960
1961 if (window) {
1962 wnck_window_set_geometry(window,
1963 WNCK_WINDOW_GRAVITY_CURRENT,
1964 WNCK_WINDOW_CHANGE_X + WNCK_WINDOW_CHANGE_Y,
1965 x, y, -1, -1);
1966 }
1967 }
1968
1969 } else {
1970 luaL_error(lua, "xy: %s", two_indata_expected_error);
1971 return 0;
1972 }
1973 return 0;
1974 }
1975
1976
1977 /**
1978 *
1979 */
1980 int c_xywh(lua_State *lua)
1981 {
1982 int top = lua_gettop(lua);
1983
1984 if (top == 0) {
1985 // Return the xywh settings of the window
1986
1987 WnckWindow *window = get_current_window();
1988 if (window != NULL) {
1989
1990 int x, y, width, height;
1991
1992 wnck_window_get_geometry(window, &x, &y, &width, &height);
1993
1994 lua_pushnumber(lua, x);
1995 lua_pushnumber(lua, y);
1996 lua_pushnumber(lua, width);
1997 lua_pushnumber(lua, height);
1998
1999 return 4;
2000 }
2001
2002 } else if (top == 4) {
2003 // Set the xywh settings in the window
2004
2005
2006 int type1 = lua_type(lua, 1);
2007 int type2 = lua_type(lua, 2);
2008 int type3 = lua_type(lua, 3);
2009 int type4 = lua_type(lua, 4);
2010
2011 if ((type1 != LUA_TNUMBER) ||
2012 (type2 != LUA_TNUMBER) ||
2013 (type3 != LUA_TNUMBER) ||
2014 (type4 != LUA_TNUMBER)) {
2015 luaL_error(lua, "xywh: %s", four_indata_expected_error);
2016 return 0;
2017 }
2018
2019 int x = lua_tonumber(lua, 1);
2020 int y = lua_tonumber(lua, 2);
2021 int xsize = lua_tonumber(lua, 3);
2022 int ysize = lua_tonumber(lua, 4);
2023
2024 if (!devilspie2_emulate) {
2025 WnckWindow *window = get_current_window();
2026
2027 set_window_geometry(window, x, y, xsize, ysize);
2028 }
2029
2030 return 0;
2031
2032 } else {
2033 luaL_error(lua, "xywh: %s", four_indata_expected_error);
2034 return 0;
2035 }
2036
2037 return 0;
2038 }
2039
2040 struct lua_callback {
2041 lua_State *lua;
2042 int ref;
2043 };
2044
2045 static void on_geometry_changed(WnckWindow *window, struct lua_callback *callback)
2046 {
2047 if (callback == NULL)
2048 return;
2049
2050 WnckWindow *old_window = get_current_window();
2051 set_current_window(window);
2052
2053 lua_rawgeti(callback->lua, LUA_REGISTRYINDEX, callback->ref);
2054 lua_pcall(callback->lua, 0, 0, 0);
2055
2056 set_current_window(old_window);
2057 }
2058
2059 static void on_geometry_changed_disconnect(gpointer data, GClosure *closure)
2060 {
2061 g_free(data);
2062 }
2063
2064 /**
2065 *
2066 */
2067 int c_on_geometry_changed(lua_State *lua)
2068 {
2069 int top = lua_gettop(lua);
2070 if (top != 1) {
2071 luaL_error(lua, "on_geometry_changed: %s", one_indata_expected_error);
2072 return 0;
2073 }
2074
2075 if (lua_type(lua, 1) != LUA_TFUNCTION) {
2076 luaL_error(lua, "on_geometry_changed: %s", "function expected");
2077 return 0;
2078 }
2079
2080 struct lua_callback *cb = g_malloc(sizeof(struct lua_callback));
2081 cb->lua = lua;
2082 cb->ref = luaL_ref(lua, LUA_REGISTRYINDEX);
2083
2084 WnckWindow *window = get_current_window();
2085
2086 if (window) {
2087 g_signal_connect_data(window, "geometry-changed", G_CALLBACK(on_geometry_changed), (gpointer)cb, (GClosureNotify)(on_geometry_changed_disconnect), 0);
2088 }
2089
2090 return 0;
2091 }
2092
2093 /*
2094 * Devilspie:
2095
2096 * Focus the current window.
2097
2098 ESExpResult *func_focus(ESExp *f, int argc, ESExpResult **argv, Context *c) {
2099 wnck_window_activate (c->window, GDK_CURRENT_TIME);
2100 if (debug) g_printerr (_("Focusing\n"));
2101 return e_sexp_result_new_bool (f, TRUE);
2102 }
2103
2104 */