Only process updates when the view is visible
parent
a5ba4c9161
commit
3e9e4208ce
|
@ -123,6 +123,9 @@ ApplicationWindow {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
processSelection.select(index, ItemSelectionModel.ToggleCurrent);
|
processSelection.select(index, ItemSelectionModel.ToggleCurrent);
|
||||||
}
|
}
|
||||||
|
Component.onCompleted: {
|
||||||
|
processes.active = Qt.binding(function() { return visible; });
|
||||||
|
}
|
||||||
width: parent.width
|
width: parent.width
|
||||||
anchors.top: processFilterInput.bottom
|
anchors.top: processFilterInput.bottom
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
|
@ -138,12 +141,12 @@ ApplicationWindow {
|
||||||
role: "name"
|
role: "name"
|
||||||
}
|
}
|
||||||
TableViewColumn {
|
TableViewColumn {
|
||||||
title: "pid"
|
title: "cpu"
|
||||||
role: "pid"
|
role: "cpuUsage"
|
||||||
}
|
}
|
||||||
TableViewColumn {
|
TableViewColumn {
|
||||||
title: "cpu"
|
title: "memory"
|
||||||
role: "cpu"
|
role: "memory"
|
||||||
}
|
}
|
||||||
onSortIndicatorColumnChanged: sort()
|
onSortIndicatorColumnChanged: sort()
|
||||||
onSortIndicatorOrderChanged: sort()
|
onSortIndicatorOrderChanged: sort()
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
"Processes": {
|
"Processes": {
|
||||||
"type": "UniformTree",
|
"type": "UniformTree",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"active": {
|
||||||
|
"type": "bool",
|
||||||
|
"write": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"itemProperties": {
|
"itemProperties": {
|
||||||
"pid": {
|
"pid": {
|
||||||
|
|
|
@ -22,7 +22,8 @@ pub struct Processes {
|
||||||
emit: ProcessesEmitter,
|
emit: ProcessesEmitter,
|
||||||
model: ProcessesUniformTree,
|
model: ProcessesUniformTree,
|
||||||
p: ProcessTree,
|
p: ProcessTree,
|
||||||
incoming: Arc<Mutex<Option<ProcessTree>>>
|
incoming: Arc<Mutex<Option<ProcessTree>>>,
|
||||||
|
active: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_process_hierarchy(parent: Option<pid_t>, processes: &HashMap<pid_t,Process>) {
|
fn check_process_hierarchy(parent: Option<pid_t>, processes: &HashMap<pid_t,Process>) {
|
||||||
|
@ -250,7 +251,8 @@ impl ProcessesTrait for Processes {
|
||||||
emit: emit.clone(),
|
emit: emit.clone(),
|
||||||
model: model,
|
model: model,
|
||||||
p: ProcessTree::default(),
|
p: ProcessTree::default(),
|
||||||
incoming: Arc::new(Mutex::new(None))
|
incoming: Arc::new(Mutex::new(None)),
|
||||||
|
active: true
|
||||||
};
|
};
|
||||||
update_thread(emit, p.incoming.clone());
|
update_thread(emit, p.incoming.clone());
|
||||||
p
|
p
|
||||||
|
@ -276,7 +278,7 @@ impl ProcessesTrait for Processes {
|
||||||
self.get(item).process.parent.map(|pid| pid as usize)
|
self.get(item).process.parent.map(|pid| pid as usize)
|
||||||
}
|
}
|
||||||
fn can_fetch_more(&self, item: Option<usize>) -> bool {
|
fn can_fetch_more(&self, item: Option<usize>) -> bool {
|
||||||
if item.is_some() {
|
if item.is_some() || !self.active {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if let Ok(ref incoming) = self.incoming.try_lock() {
|
if let Ok(ref incoming) = self.incoming.try_lock() {
|
||||||
|
@ -286,7 +288,7 @@ impl ProcessesTrait for Processes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn fetch_more(&mut self, item: Option<usize>) {
|
fn fetch_more(&mut self, item: Option<usize>) {
|
||||||
if item.is_some() {
|
if item.is_some() || !self.active {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let new = if let Ok(ref mut incoming) = self.incoming.try_lock() {
|
let new = if let Ok(ref mut incoming) = self.incoming.try_lock() {
|
||||||
|
@ -334,4 +336,10 @@ impl ProcessesTrait for Processes {
|
||||||
fn cmd(&self, item: usize) -> String {
|
fn cmd(&self, item: usize) -> String {
|
||||||
self.process(item).cmd.join(" ")
|
self.process(item).cmd.join(" ")
|
||||||
}
|
}
|
||||||
|
fn get_active(&self) -> bool {
|
||||||
|
self.active
|
||||||
|
}
|
||||||
|
fn set_active(&mut self, active: bool) {
|
||||||
|
self.active = active
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ pub struct ProcessesQObject {}
|
||||||
#[derive (Clone)]
|
#[derive (Clone)]
|
||||||
pub struct ProcessesEmitter {
|
pub struct ProcessesEmitter {
|
||||||
qobject: Arc<Mutex<*const ProcessesQObject>>,
|
qobject: Arc<Mutex<*const ProcessesQObject>>,
|
||||||
|
active_changed: fn(*const ProcessesQObject),
|
||||||
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +89,12 @@ impl ProcessesEmitter {
|
||||||
fn clear(&self) {
|
fn clear(&self) {
|
||||||
*self.qobject.lock().unwrap() = null();
|
*self.qobject.lock().unwrap() = null();
|
||||||
}
|
}
|
||||||
|
pub fn active_changed(&self) {
|
||||||
|
let ptr = *self.qobject.lock().unwrap();
|
||||||
|
if !ptr.is_null() {
|
||||||
|
(self.active_changed)(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn new_data_ready(&self, item: Option<usize>) {
|
pub fn new_data_ready(&self, item: Option<usize>) {
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
let ptr = *self.qobject.lock().unwrap();
|
||||||
if !ptr.is_null() {
|
if !ptr.is_null() {
|
||||||
|
@ -134,6 +141,8 @@ impl ProcessesUniformTree {
|
||||||
pub trait ProcessesTrait {
|
pub trait ProcessesTrait {
|
||||||
fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Self;
|
fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Self;
|
||||||
fn emit(&self) -> &ProcessesEmitter;
|
fn emit(&self) -> &ProcessesEmitter;
|
||||||
|
fn get_active(&self) -> bool;
|
||||||
|
fn set_active(&mut self, value: bool);
|
||||||
fn row_count(&self, Option<usize>) -> usize;
|
fn row_count(&self, Option<usize>) -> usize;
|
||||||
fn can_fetch_more(&self, Option<usize>) -> bool { false }
|
fn can_fetch_more(&self, Option<usize>) -> bool { false }
|
||||||
fn fetch_more(&mut self, Option<usize>) {}
|
fn fetch_more(&mut self, Option<usize>) {}
|
||||||
|
@ -152,6 +161,7 @@ pub trait ProcessesTrait {
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn processes_new(processes: *mut ProcessesQObject,
|
pub extern "C" fn processes_new(processes: *mut ProcessesQObject,
|
||||||
|
active_changed: fn(*const ProcessesQObject),
|
||||||
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
||||||
data_changed: fn(*const ProcessesQObject, usize, usize),
|
data_changed: fn(*const ProcessesQObject, usize, usize),
|
||||||
begin_reset_model: fn(*const ProcessesQObject),
|
begin_reset_model: fn(*const ProcessesQObject),
|
||||||
|
@ -167,6 +177,7 @@ pub extern "C" fn processes_new(processes: *mut ProcessesQObject,
|
||||||
-> *mut Processes {
|
-> *mut Processes {
|
||||||
let processes_emit = ProcessesEmitter {
|
let processes_emit = ProcessesEmitter {
|
||||||
qobject: Arc::new(Mutex::new(processes)),
|
qobject: Arc::new(Mutex::new(processes)),
|
||||||
|
active_changed: active_changed,
|
||||||
new_data_ready: new_data_ready,
|
new_data_ready: new_data_ready,
|
||||||
};
|
};
|
||||||
let model = ProcessesUniformTree {
|
let model = ProcessesUniformTree {
|
||||||
|
@ -188,6 +199,16 @@ pub unsafe extern "C" fn processes_free(ptr: *mut Processes) {
|
||||||
Box::from_raw(ptr).emit().clear();
|
Box::from_raw(ptr).emit().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn processes_active_get(ptr: *const Processes) -> bool {
|
||||||
|
(&*ptr).get_active()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn processes_active_set(ptr: *mut Processes, v: bool) {
|
||||||
|
(&mut *ptr).set_active(v);
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn processes_row_count(ptr: *const Processes, item: usize, valid: bool) -> c_int {
|
pub unsafe extern "C" fn processes_row_count(ptr: *const Processes, item: usize, valid: bool) -> c_int {
|
||||||
if valid {
|
if valid {
|
||||||
|
|
|
@ -44,6 +44,10 @@ namespace {
|
||||||
int row;
|
int row;
|
||||||
quintptr id;
|
quintptr id;
|
||||||
};
|
};
|
||||||
|
inline void processesActiveChanged(Processes* o)
|
||||||
|
{
|
||||||
|
emit o->activeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
typedef void (*qstring_set)(QString*, qstring_t*);
|
||||||
|
@ -210,7 +214,7 @@ bool Processes::setData(const QModelIndex &index, const QVariant &value, int rol
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Processes::Private* processes_new(Processes*,
|
Processes::Private* processes_new(Processes*, void (*)(Processes*),
|
||||||
void (*)(const Processes*, quintptr, bool),
|
void (*)(const Processes*, quintptr, bool),
|
||||||
void (*)(Processes*, quintptr, quintptr),
|
void (*)(Processes*, quintptr, quintptr),
|
||||||
void (*)(Processes*),
|
void (*)(Processes*),
|
||||||
|
@ -220,6 +224,8 @@ extern "C" {
|
||||||
void (*)(Processes*, option<quintptr>, int, int),
|
void (*)(Processes*, option<quintptr>, int, int),
|
||||||
void (*)(Processes*));
|
void (*)(Processes*));
|
||||||
void processes_free(Processes::Private*);
|
void processes_free(Processes::Private*);
|
||||||
|
bool processes_active_get(const Processes::Private*);
|
||||||
|
void processes_active_set(Processes::Private*, bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
Processes::Processes(bool /*owned*/, QObject *parent):
|
Processes::Processes(bool /*owned*/, QObject *parent):
|
||||||
|
@ -232,6 +238,7 @@ Processes::Processes(bool /*owned*/, QObject *parent):
|
||||||
Processes::Processes(QObject *parent):
|
Processes::Processes(QObject *parent):
|
||||||
QAbstractItemModel(parent),
|
QAbstractItemModel(parent),
|
||||||
m_d(processes_new(this,
|
m_d(processes_new(this,
|
||||||
|
processesActiveChanged,
|
||||||
[](const Processes* o, quintptr id, bool valid) {
|
[](const Processes* o, quintptr id, bool valid) {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
int row = processes_row(o->m_d, id);
|
int row = processes_row(o->m_d, id);
|
||||||
|
@ -287,3 +294,10 @@ Processes::~Processes() {
|
||||||
processes_free(m_d);
|
processes_free(m_d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool Processes::active() const
|
||||||
|
{
|
||||||
|
return processes_active_get(m_d);
|
||||||
|
}
|
||||||
|
void Processes::setActive(bool v) {
|
||||||
|
processes_active_set(m_d, v);
|
||||||
|
}
|
||||||
|
|
|
@ -15,10 +15,13 @@ public:
|
||||||
private:
|
private:
|
||||||
Private * m_d;
|
Private * m_d;
|
||||||
bool m_ownsPrivate;
|
bool m_ownsPrivate;
|
||||||
|
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged FINAL)
|
||||||
explicit Processes(bool owned, QObject *parent);
|
explicit Processes(bool owned, QObject *parent);
|
||||||
public:
|
public:
|
||||||
explicit Processes(QObject *parent = nullptr);
|
explicit Processes(QObject *parent = nullptr);
|
||||||
~Processes();
|
~Processes();
|
||||||
|
bool active() const;
|
||||||
|
void setActive(bool v);
|
||||||
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
@ -36,5 +39,6 @@ signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
signals:
|
signals:
|
||||||
|
void activeChanged();
|
||||||
};
|
};
|
||||||
#endif // PROCESSES_H
|
#endif // PROCESSES_H
|
||||||
|
|
Loading…
Reference in New Issue