2 # vim:ts=4:sw=4:expandtab
4 # Test for the startup notification protocol.
9 use File::Temp qw(:POSIX);
11 my $x = X11::XCB::Connection->new;
12 use ExtUtils::PkgConfig;
14 # setup dependency on libstartup-notification using pkg-config
17 %sn_config = ExtUtils::PkgConfig->find('libstartup-notification-1.0');
20 use Inline C => Config => LIBS => $sn_config{libs}, CCFLAGS => $sn_config{cflags};
21 use Inline C => <<'END_OF_C_CODE';
25 #define SN_API_NOT_YET_FROZEN 1
26 #include <libsn/sn-common.h>
27 #include <libsn/sn-launchee.h>
29 static SnDisplay *sndisplay;
30 static SnLauncheeContext *ctx;
31 static xcb_connection_t *conn;
33 // TODO: this should use $x
36 if ((conn = xcb_connect(NULL, &screen)) == NULL ||
37 xcb_connection_has_error(conn))
38 errx(1, "x11 conn failed");
40 printf("screen = %d\n", screen);
41 sndisplay = sn_xcb_display_new(conn, NULL, NULL);
42 ctx = sn_launchee_context_new_from_environment(sndisplay, screen);
45 const char *get_startup_id() {
46 return sn_launchee_context_get_startup_id(ctx);
49 void mark_window(int window) {
50 sn_launchee_context_setup_window(ctx, (Window)window);
54 void complete_startup() {
55 /* mark the startup process complete */
56 sn_launchee_context_complete(ctx);
60 my $first_ws = fresh_workspace;
62 is(@{get_ws_content($first_ws)}, 0, 'no containers on this workspace yet');
64 ######################################################################
65 # 1) initiate startup, switch workspace, create window
66 # (should be placed on the original workspace)
67 ######################################################################
69 # Start a new process via i3 (to initialize a new startup notification
70 # context), then steal its DESKTOP_STARTUP_ID variable. We handle the startup
71 # notification in the testcase from there on.
73 # This works by setting up a FIFO in which the process (started by i3) will
74 # echo its $DESKTOP_STARTUP_ID. We (blockingly) read the variable into
75 # $startup_id in the testcase.
77 mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
79 cmd qq|exec echo \$DESKTOP_STARTUP_ID >$tmp|;
81 open(my $fh, '<', $tmp);
82 chomp(my $startup_id = <$fh>);
87 isnt($startup_id, '', 'startup_id not empty');
89 $ENV{DESKTOP_STARTUP_ID} = $startup_id;
91 # Create a new libstartup-notification launchee context
94 # Make sure the context was set up successfully
95 is(get_startup_id(), $startup_id, 'libstartup-notification returns the same id');
97 my $second_ws = fresh_workspace;
99 is(@{get_ws_content($second_ws)}, 0, 'no containers on the second workspace yet');
101 my $win = open_window($x, { dont_map => 1 });
102 mark_window($win->id);
104 # We don’t use wait_for_map because the window will not get mapped -- it is on
105 # a different workspace.
106 # We sync with i3 here to make sure $x->input_focus is updated.
109 is(@{get_ws_content($second_ws)}, 0, 'still no containers on the second workspace');
110 is(@{get_ws_content($first_ws)}, 1, 'one container on the first workspace');
112 ######################################################################
113 # same thing, but with _NET_STARTUP_ID set on the leader
114 ######################################################################
116 my $leader = open_window($x, { dont_map => 1 });
117 mark_window($leader->id);
119 $win = open_window($x, { dont_map => 1, client_leader => $leader });
123 is(@{get_ws_content($second_ws)}, 0, 'still no containers on the second workspace');
124 is(@{get_ws_content($first_ws)}, 2, 'two containers on the first workspace');
126 ######################################################################
127 # 2) open another window after the startup process is completed
128 # (should be placed on the current workspace)
129 ######################################################################
134 my $otherwin = open_window($x);
135 is(@{get_ws_content($second_ws)}, 1, 'one container on the second workspace');
137 ######################################################################
138 # 3) test that the --no-startup-id flag for exec leads to no DESKTOP_STARTUP_ID
139 # environment variable.
140 ######################################################################
142 mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
144 cmd qq|exec --no-startup-id echo \$DESKTOP_STARTUP_ID >$tmp|;
146 open($fh, '<', $tmp);
147 chomp($startup_id = <$fh>);
152 is($startup_id, '', 'startup_id empty');
154 ######################################################################
155 # 4) same thing, but with double quotes in exec
156 ######################################################################
158 mkfifo($tmp, 0600) or die "Could not create FIFO in $tmp";
160 cmd qq|exec --no-startup-id "echo \$DESKTOP_STARTUP_ID >$tmp"|;
162 open($fh, '<', $tmp);
163 chomp($startup_id = <$fh>);
168 is($startup_id, '', 'startup_id empty');