File: afloatwidget.cpp

package info (click to toggle)
aeskulap 0.2.2b1%2Bgit20161206-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,840 kB
  • ctags: 1,302
  • sloc: cpp: 8,894; sh: 5,551; ansic: 685; makefile: 317; xml: 25
file content (91 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "afloatwidget.h"
#include <iostream>

namespace Aeskulap {

std::set<FloatWidget*> FloatWidget::m_widgetlist;

FloatWidget::FloatWidget(Gtk::Widget& parent, int width, int height) :
m_width(width),
m_height(height) {
	m_parent = &parent;

	resize(m_width, m_height);
	set_decorated(false);
	set_keep_above();
	set_skip_taskbar_hint(true);
	set_skip_pager_hint(true);
	set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
	reparent(parent);
	
	m_widgetlist.insert(this);
}

FloatWidget::~FloatWidget() {
	m_motion_connection.disconnect();
	m_widgetlist.erase(this);
}

void FloatWidget::on_show() {
	m_motion_connection = Glib::signal_timeout().connect(sigc::bind(sigc::mem_fun(*this, &FloatWidget::on_timeout), 1), 50);
	Gtk::Window::on_show();
}

void FloatWidget::on_hide() {
	m_motion_connection.disconnect();
	Gtk::Window::on_hide();
}
	

void FloatWidget::on_realize() {
	Gtk::Window::on_realize();
	get_window()->reparent(m_parent->get_window(), 0, 0);
}

bool FloatWidget::on_timeout(int timer) {
	int x, x1;
	int y, y1;
	
	m_parent->get_pointer(x, y);
	if(x < 0 || y < 0) {
		return true;
	}

	if(x >= m_parent->get_width() || y >= m_parent->get_height()) {
		return true;
	}

	if(!m_parent->is_visible() || !m_parent->is_realized()) {
		return true;
	}
		
	m_parent->get_pointer(x, y);
	//get_position(x, y);
	/*get_pointer(x1, y1);

	x += x1;
	y += y1;*/

	x += 16;
	y += 16;

	if(x != last_x || y != last_y) {
		move(x, y);
		
		last_x = x;
		last_y = y;
	}

	return true;
}

void FloatWidget::raise_global() {
	std::set<FloatWidget*>::iterator i;
	for(i = m_widgetlist.begin(); i != m_widgetlist.end(); i++) {
		if((*i)->is_visible()) {
			(*i)->raise();
		}
	}
}

} // namespace Aeskulap