Sponsored Content
Special Forums UNIX and Linux Applications Rectangle is flickering while dragging on screen with xlib Post 302907014 by whatnext on Wednesday 25th of June 2014 10:01:25 AM
Old 06-25-2014
Rectangle is flickering while dragging on screen with xlib

Hi, this is my first post here.

I wanto make a screencasting program. I want to make a screen part selection to grab coordinates of the screen location.
I found a nice prototype

Code:
#include <X11/Xlib.h>
//#include <X11/Xresource.h>

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main()
{
    Display *dpy;
    XEvent ev;

    GC sel_gc;
    XGCValues sel_gv;

    int x, y, i;
    int start_x, start_y, width, height;


    if (!(dpy = XOpenDisplay(NULL))) {
        fprintf(stderr, "Could not open display %s", getenv("DISPLAY"));
    }

    XGrabButton(dpy, 1, 0, DefaultRootWindow(dpy), True, ButtonPressMask, GrabModeSync, GrabModeAsync, None, None);

    sel_gv.function = GXinvert;
    sel_gv.subwindow_mode = IncludeInferiors;
    sel_gv.line_width = 1;
    sel_gc = XCreateGC(dpy, DefaultRootWindow(dpy), GCFunction | GCSubwindowMode | GCLineWidth, &sel_gv);

    for (;;) {
        XNextEvent(dpy, &ev);

        if (ev.type == ButtonPress) {
            /* Grab pointer so we receive ButtonRelease */
            XGrabPointer(dpy, DefaultRootWindow(dpy), True, PointerMotionMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
            x = start_x = ev.xbutton.x_root;
            y = start_y = ev.xbutton.y_root;

            width = height = 0;

            //XAllowEvents(dpy, ReplayPointer, CurrentTime); /* Allow other apps to process this message */
        } else if (ev.type == MotionNotify) {
            while (XCheckTypedEvent(dpy, MotionNotify, &ev));

            XDrawRectangle(dpy, DefaultRootWindow(dpy), sel_gc, x, y, width, height); /* Clear Rectangle */

            width = ev.xbutton.x_root - start_x;
            height = ev.xbutton.y_root - start_y;

            /* Ugliness to make width/height positive and put the start positions
             * in the right place so we can draw backwards basically. */
            if (width < 0) { width = abs(width); x = ev.xbutton.x_root; } else { x = start_x; }
            if (height < 0) { height = abs(height); y = ev.xbutton.y_root; } else { y = start_y; }

            XDrawRectangle(dpy, DefaultRootWindow(dpy), sel_gc, x, y, width, height); /* Draw Rectangle */
        } else if (ev.type == ButtonRelease) {
            XUngrabPointer(dpy, CurrentTime);

            XDrawRectangle(dpy, DefaultRootWindow(dpy), sel_gc, x, y, width, height); /* Clear Rectangle */

            XSync(dpy, 1); /* Needed to Ungrab Pointer NOW otherwise we continue receiving MotionNotify events and the previous line is useless */

            printf("%i %i %i %i\n", x, y, width, height);
        }
    }

    XFreeGC(dpy, sel_gc);

    XCloseDisplay(dpy);

    return 0;
}

I am on Ubuntu 14.04 platform, I compiled and run the code. While dragging mouse I get flickering and partially missing rectangle. I wonder if it's specific to my system or xlib library deprecated?

Would anybody here help me fix it please?
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

xlib error

Hello! Im running tight VNC on Red Hat Enterprise Linux 4.0. How can I increase the number of X clients that I can run in a VNC session?I need to run aproximately 500 programs in one VNC session, but at this time I can only 236 -> i've tryed to launch 250 xclock's in background and when it... (3 Replies)
Discussion started by: karpoand
3 Replies

2. OS X (Apple)

Virtual screen accessed by Screen Sharing

Hi, I'm trying to create a virtual screen, (maybe xvfb? or any other virtual screen buffer) and be able to use Screen Sharing to connect to it. The setup is that I have a Mac Mini connected to the TV. But when my girlfriend is using Front Row, I can't use Screen Sharing at the same time from... (0 Replies)
Discussion started by: linge
0 Replies

3. Ubuntu

laptop - flickering display

i have installed ubuntu 9.0.4 on my laptop and i have a display problem my laptop display flickers from time to time while i am using it and to me it is kind of annoying please reply thanks (8 Replies)
Discussion started by: mhilinski
8 Replies

4. UNIX and Linux Applications

xlib: allow overlay of other windows in full-screen

Hi, I am using the feh slideshow program in full-screen mode. While the slide show is in progress I would like to draw some other windows (something like clock or calendar from gdesklets) on top of this slideshow. Currently feh does not allow me to do that. Below is the code that feh uses to... (0 Replies)
Discussion started by: aerosmith
0 Replies

5. Red Hat

#service --status-all : screen flickering

hi there when i run #service --status-all or #service nfs status the screen flickers if i ssh from remote system than i dont have flickering on the remote nor that system. is it something to do with probably display configuration. ? and which file are the display setting... (7 Replies)
Discussion started by: dplinux
7 Replies

6. UNIX for Dummies Questions & Answers

Xlib Errors

Hi, I am handling user issues in my team. Users have their Unix session running on Citrix MFU. Recently, I was suppose to address a user issue which is as below: Gets the below error when tries to open nedit: Xlib: connection to ":165.0" refused by server Xlib: Client is not... (1 Reply)
Discussion started by: mspatil0037
1 Replies

7. Red Hat

command line tool to disable screen lock and/or screen saver

Hi, I have a simple question : how to disable screen lock and/or sreen saver with command line with RHEL5.4 ? (1 Reply)
Discussion started by: albator1932
1 Replies

8. UNIX for Advanced & Expert Users

Xlib: XKeysymToKeycode hangs

Two simple questions related to the following puzzling behaviour: I have the following line of code: const KeyCode kc = XKeysymToKeycode(_display_p, ks); where _display_p is a valid Display* returned from XOpenDisplay() and ks has the value 103 (which was returned by XStringToKeysym(),... (2 Replies)
Discussion started by: N7DR
2 Replies

9. UNIX for Dummies Questions & Answers

Accidentally made a screen within a screen - how to move it up one level?

I made a screen within a screen. Is there a way to move the inner screen up one level so that it is at the same level as the first screen running from the shell? (2 Replies)
Discussion started by: phpchick
2 Replies

10. Programming

Xlib registering

hey, Im new to the linux world. Lately, I have tried to create a glx window with xlib, making it a popup window(fullscreen) so I set override_redirect to true. Im happy with the removed borders, but apparantly, the application doesnt show up in the left bar in ubuntu, neither when I press alt... (4 Replies)
Discussion started by: thedardanius
4 Replies
Gtk2::ImageView::Tool::Selector(3pm)			User Contributed Perl Documentation		      Gtk2::ImageView::Tool::Selector(3pm)

NAME
Gtk2::ImageView::Tool::Selector - Image tool for selecting rectangular regions HIERARCHY
Glib::Object +----Gtk2::ImageView::Tool::Selector INTERFACES
Gtk2::ImageView::Tool DESCRIPTION
Gtk2::ImageView::Tool::Selector is a tool for selecting areas of an image. It is useful for cropping an image, for example. The tool is an implementor of the Gtk2::ImageView::Tool inteface which means that it can be plugged into a Gtk2::ImageView by using the Gtk2::ImageView::Tool::set_tool() method. Gtk2::ImageView::Tool::Selector changes the default display of the Gtk2::ImageView. It darkens down the unselected region of the image which provides a nice effect and makes it clearer what part of the image that is currently selected. Unfortunately, this effect is somewhat incompatible with how Gtk2::ImageView::Nav behaves because that widget will show the image without darkening it. The tool also changes the default behaviour of the mouse. When a Gtk2::ImageView::Tool::Selector is set on a Gtk2::ImageView, mouse presses do not "grab" the image and you cannot scroll by dragging. Instead mouse presses and dragging is used to resize and move the selection rectangle. When the mouse drags the selection rectangle to the border of the widget, the view autoscrolls which is a convenient way for a user to position the selection. Please note that Gtk2::ImageView::Tool::Selector draws the image in two layers. One darkened and the selection rectangle in normal luminosity. Because it uses two draw operations instead one one like Gtk2::ImageView::Tool::Dragger does, it is significantly slower than that tool. Therefore, it makes sense for a user of this library to set the interpolation to GDK_INTERP_NEAREST when using this tool to ensure that performance is acceptable to the users of the program. Zoom bug There is a small bug in Gtk2::ImageView::Tool::Selector that becomes apparent when the zoom factor is greater than about 30. The edge of the selection rectangle may in that case intersect a pixel. The bug is caused by bug 389832 in gdk-pixbuf. There is no way to solve this bug on Gtk2::ImageView's level (but if someone knows how, I'd really like to know). METHODS
tool = Gtk2::ImageView::Tool::Selector->new ($view) o $view (Gtk2::ImageView) Returns a new selector tool for the specified view with the following default values: selection : (0, 0) - [0, 0] rectangle = $selector->get_selection Returns a Gtk2::Gdk::Rectangle with the current selection. If either the width or the height of the selection is zero, then nothing is selected and undef is returned. See "selection-changed" for an example. $selector->set_selection ($rect) o $rect (Gtk2::Gdk::Rectangle) Sets the selection rectangle for the tool. Setting this attribute will cause the widget to immidiately repaint itself if its view is realized. This method does nothing under the following circumstances: If the views pixbuf is undef. If rect is wider or taller than the size of the pixbuf If rect equals the current selection rectangle. If the selection falls outside the pixbufs area, its position is moved so that it is within the pixbuf. Calling this method causes the ::selection-changed signal to be emitted. The default selection is (0,0) - [0,0]. selector : a Gtk2::ImageView::Tool::Selector rect : Selection rectangle in image space coordinates. PROPERTIES
'view' (Gtk2::ImageView : default undef : writable / construct-only) Image View to navigate SIGNALS
selection-changed (Gtk2::ImageView::Tool::Selector) SEE ALSO
Gtk2::ImageView, Glib::Object COPYRIGHT
Copyright (C) 2007 by Jeffrey Ratcliffe. This software is licensed under the GPL-3; see Gtk2::ImageView for a full notice. perl v5.14.2 2011-11-16 Gtk2::ImageView::Tool::Selector(3pm)
All times are GMT -4. The time now is 05:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy