2
* Copyright © 2012 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
19
#include <ubuntu/ui/ubuntu_ui_session_service.h>
42
Config() : take_screencast_flag(0),
43
take_screenshot_flag(0)
47
int take_screencast_flag;
48
int take_screenshot_flag;
51
void on_snapshot_completed(const void* pixel_data, unsigned int width, unsigned int height, unsigned int x, unsigned int y, unsigned int source_width, unsigned int source_height, unsigned int stride, void* context)
53
static unsigned int counter = 0;
55
printf("%s: (%p, %d, %d, %d) \n",
62
static const char snapshot_pattern[] = "./snapshot_%I_%M_%S.ppm";
63
static const char frame_pattern[] = "./frame_%I_%M_%S.raw";
67
int take_screenshot = 1;
68
int take_screencast = 0;
72
Config* config = (Config*) context;
74
take_screenshot = config->take_screenshot_flag;
75
take_screencast = config->take_screencast_flag;
81
curtime = time (NULL);
82
loctime = localtime (&curtime);
84
static const char screenshot_file_mode[] = "w+";
85
static const char screencast_file_mode[] = "wb+";
90
strftime(fn, 256, snapshot_pattern, loctime);
91
f = fopen(fn, screenshot_file_mode);
92
} else if (take_screencast)
94
strftime(fn, 256, frame_pattern, loctime);
95
f = fopen(fn, screencast_file_mode);
100
printf("Problem opening file: %s \n", fn);
106
const unsigned int* p = static_cast<const unsigned int*>(pixel_data);
108
fprintf(f, "P3\n%d %d\n%d\n\n", width, height, 255);
109
for(unsigned int i = 0; i < height; i++)
111
for(unsigned int j = 0; j < width; j++)
113
Pixel pixel; pixel.value = *p; ++p;
122
else if (take_screencast)
124
fwrite(pixel_data, sizeof(unsigned int), width*height, f);
125
ubuntu_ui_session_snapshot_running_session_with_id(
127
on_snapshot_completed,
132
void on_session_born(ubuntu_ui_session_properties props, void*)
134
printf("%s:\n\t Id: %d \n\t Desktop file hint: %s \n",
136
ubuntu_ui_session_properties_get_application_instance_id(props),
137
ubuntu_ui_session_properties_get_desktop_file_hint(props));
139
ubuntu_ui_session_snapshot_running_session_with_id(
140
ubuntu_ui_session_properties_get_application_instance_id(props),
141
on_snapshot_completed,
145
void on_session_focused(ubuntu_ui_session_properties props, void*)
147
printf("%s:\n\t Id: %d \n\t Desktop file hint: %s \n",
149
ubuntu_ui_session_properties_get_application_instance_id(props),
150
ubuntu_ui_session_properties_get_desktop_file_hint(props));
153
void on_session_died(ubuntu_ui_session_properties props, void*)
155
printf("%s:\n\t Id: %d \n\t Desktop file hint: %s \n",
157
ubuntu_ui_session_properties_get_application_instance_id(props),
158
ubuntu_ui_session_properties_get_desktop_file_hint(props));
163
Config parse_cmd_line(int argc, char** argv)
166
static struct option long_options[] = {
167
{"take-screencast", no_argument, &config.take_screencast_flag, 1},
168
{"take-screenshot", no_argument, &config.take_screenshot_flag, 1}
173
int option_index = 0;
188
// No need to do anything here: Flag is set automatically.
198
int main(int argc, char** argv)
200
static const int complete_session_id = -1;
202
Config config = parse_cmd_line(argc, argv);
204
if (config.take_screenshot_flag || config.take_screencast_flag)
206
ubuntu_ui_session_snapshot_running_session_with_id(
208
on_snapshot_completed,
214
ubuntu_ui_session_lifecycle_observer observer;
216
memset(&observer, 0, sizeof(observer));
217
observer.on_session_born = on_session_born;
218
observer.on_session_focused = on_session_focused;
219
observer.on_session_died = on_session_died;
221
ubuntu_ui_session_install_session_lifecycle_observer(&observer);