From 4468f577991cd86e844c3a5929e3b0d6e1ff3b45 Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 2 Oct 2012 18:37:09 +0200 Subject: initial --- xcb01.cpp | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xcb02.cpp | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 348 insertions(+) create mode 100644 xcb01.cpp create mode 100644 xcb02.cpp diff --git a/xcb01.cpp b/xcb01.cpp new file mode 100644 index 0000000..8d9b1b4 --- /dev/null +++ b/xcb01.cpp @@ -0,0 +1,166 @@ +/* + * unbenannt.cxx + * + * Copyright 2012 Unknown + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include +#include +#include +#include +#include + +using namespace std; + +int main(int argc, char **argv) +{ + xcb_connection_t* conn; + conn=xcb_connect(NULL,NULL); + + bool found_win=false; + xcb_window_t grabbed_win; + int grab_width, grab_height; + xcb_screen_t* grab_screen=NULL; + + /* Find configured screen */ + const xcb_setup_t *setup = xcb_get_setup(conn); + xcb_screen_t *scr = NULL; + for (xcb_screen_iterator_t i = xcb_setup_roots_iterator(setup); + i.rem > 0; xcb_screen_next (&i)) + { + xcb_screen_t* scr = i.data; + xcb_query_tree_reply_t* reply = xcb_query_tree_reply( conn, xcb_query_tree(conn, scr->root), NULL); + if (reply) + { + int len = xcb_query_tree_children_length(reply); + xcb_window_t* children = xcb_query_tree_children(reply); + xcb_get_window_attributes_cookie_t* cookies = new xcb_get_window_attributes_cookie_t[len]; + for (int i=0; ioverride_redirect && attr->map_state == XCB_MAP_STATE_VIEWABLE) + { + char* title=(char*)(title_reply+1); + cout << title << endl; + if (strstr(title, "Mupen64Plus OpenGL Video")) + { + grabbed_win=children[i]; + found_win=true; + + /* Window properties */ + xcb_get_geometry_reply_t *geo; + geo = xcb_get_geometry_reply (conn, + xcb_get_geometry (conn, grabbed_win), + NULL); + if (geo == NULL) + { + cerr << "geo==NULL!" << endl; + exit(1); + } + + grab_width=geo->width; + grab_height=geo->height; + + free(geo); + + grab_screen=scr; + } + } + + free(title_reply); + free(attr); + } + + free(reply); + delete[] cookies; + } + } + + if (found_win) + { + xcb_get_image_reply_t* img = xcb_get_image_reply (conn, + xcb_get_image (conn, XCB_IMAGE_FORMAT_Z_PIXMAP, grabbed_win, + 0, 0, grab_width, grab_height, ~0), NULL); + + + + xcb_depth_iterator_t depth_iterator = xcb_screen_allowed_depths_iterator(grab_screen); + + int ndepths=xcb_screen_allowed_depths_length(grab_screen); + + for (int i=0; idepth == img->depth) + { + xcb_visualtype_t* visuals = xcb_depth_visuals(depth_iterator.data); + int nvisuals = xcb_depth_visuals_length(depth_iterator.data); + + for (int j=0;jvisual) + { + assert(visuals[j]._class==XCB_VISUAL_CLASS_TRUE_COLOR || visuals[j]._class==XCB_VISUAL_CLASS_DIRECT_COLOR); + cout << (int)visuals[j]._class << "," << XCB_VISUAL_CLASS_TRUE_COLOR << endl; + cout << visuals[j].red_mask << endl; + cout << visuals[j].green_mask << endl; + cout << visuals[j].blue_mask << endl; + break; + } + } + + break; + } + + xcb_depth_next(&depth_iterator); + } + + + + int nformats = xcb_setup_pixmap_formats_length(setup); + xcb_format_t* formats = xcb_setup_pixmap_formats(setup); + for (int i=0;idepth) + { + cout << (int)formats[i].bits_per_pixel << endl; + cout << (int)formats[i].scanline_pad << endl; + break; + } + } + + cout << grab_width << "x" << grab_height << endl; + } + else + cerr << "FATAL: did not find window, exiting." << endl; + + + xcb_disconnect(conn); + return 0; +} + diff --git a/xcb02.cpp b/xcb02.cpp new file mode 100644 index 0000000..29c0bd6 --- /dev/null +++ b/xcb02.cpp @@ -0,0 +1,182 @@ +/* + * unbenannt.cxx + * + * Copyright 2012 Unknown + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include +#include +#include +#include +#include + +#include + +using namespace std; +using namespace cv; + +int main(int argc, char **argv) +{ + xcb_connection_t* conn; + conn=xcb_connect(NULL,NULL); + + bool found_win=false; + xcb_window_t grabbed_win; + int grab_width, grab_height; + xcb_screen_t* grab_screen=NULL; + + /* Find configured screen */ + const xcb_setup_t *setup = xcb_get_setup(conn); + xcb_screen_t *scr = NULL; + for (xcb_screen_iterator_t i = xcb_setup_roots_iterator(setup); + i.rem > 0; xcb_screen_next (&i)) + { + xcb_screen_t* scr = i.data; + xcb_query_tree_reply_t* reply = xcb_query_tree_reply( conn, xcb_query_tree(conn, scr->root), NULL); + if (reply) + { + int len = xcb_query_tree_children_length(reply); + xcb_window_t* children = xcb_query_tree_children(reply); + xcb_get_window_attributes_cookie_t* cookies = new xcb_get_window_attributes_cookie_t[len]; + for (int i=0; ioverride_redirect && attr->map_state == XCB_MAP_STATE_VIEWABLE) + { + char* title=(char*)(title_reply+1); + cout << title << endl; + if (strstr(title, "Mupen64Plus OpenGL Video")) + { + grabbed_win=children[i]; + found_win=true; + + /* Window properties */ + xcb_get_geometry_reply_t *geo; + geo = xcb_get_geometry_reply (conn, + xcb_get_geometry (conn, grabbed_win), + NULL); + if (geo == NULL) + { + cerr << "geo==NULL!" << endl; + exit(1); + } + + grab_width=geo->width; + grab_height=geo->height; + + free(geo); + + grab_screen=scr; + } + } + + free(title_reply); + free(attr); + } + + free(reply); + delete[] cookies; + } + } + + if (found_win) + { + xcb_get_image_reply_t* img = xcb_get_image_reply (conn, + xcb_get_image (conn, XCB_IMAGE_FORMAT_Z_PIXMAP, grabbed_win, + 0, 0, grab_width, grab_height, ~0), NULL); + + + + xcb_depth_iterator_t depth_iterator = xcb_screen_allowed_depths_iterator(grab_screen); + + int ndepths=xcb_screen_allowed_depths_length(grab_screen); + + for (int i=0; idepth == img->depth) + { + xcb_visualtype_t* visuals = xcb_depth_visuals(depth_iterator.data); + int nvisuals = xcb_depth_visuals_length(depth_iterator.data); + + for (int j=0;jvisual) + { + assert(visuals[j]._class==XCB_VISUAL_CLASS_TRUE_COLOR || visuals[j]._class==XCB_VISUAL_CLASS_DIRECT_COLOR); + cout << (int)visuals[j]._class << "," << XCB_VISUAL_CLASS_TRUE_COLOR << endl; + cout << visuals[j].red_mask << endl; + cout << visuals[j].green_mask << endl; + cout << visuals[j].blue_mask << endl; + break; + } + } + + break; + } + + xcb_depth_next(&depth_iterator); + } + + + + int nformats = xcb_setup_pixmap_formats_length(setup); + xcb_format_t* formats = xcb_setup_pixmap_formats(setup); + for (int i=0;idepth) + { + cout << (int)formats[i].bits_per_pixel << endl; + cout << (int)formats[i].scanline_pad << endl; + break; + } + } + + cout << grab_width << "x" << grab_height << endl; + + while(1) + { + Mat meh(grab_height, grab_width, CV_8UC4, xcb_get_image_data(img)); + namedWindow("meh"); + imshow("meh", meh); + waitKey(50); + img = xcb_get_image_reply (conn, + xcb_get_image (conn, XCB_IMAGE_FORMAT_Z_PIXMAP, grabbed_win, + 0, 0, grab_width, grab_height, ~0), NULL); + + } + + } + else + cerr << "FATAL: did not find window, exiting." << endl; + + + xcb_disconnect(conn); + return 0; +} + -- cgit v1.2.3